Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Fail Over and Identities

Author  Topic 

scottpt
Posting Yak Master

186 Posts

Posted - 2003-05-02 : 13:23:18
We have a replicated fail over solution. We replicate the indentity PK as integers to simplify replication. When we fail over to the replicated server, how do you switch that column to an identity column?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-05-02 : 13:54:45
You will need to create a temporary table that has the identity option set. Then transfer the data over to the temporary table from the replicated table (you will need to turn on IDENTITY_INSERT, see BOL for information about this). Then drop the replicated table, then rename the temporary table to the name of the replicated table that was just dropped. Don't forget about your PKs, FKs, constraints, etc...

BTW, I don't usually recommend using Enterprise Manager for any DDL, but...

If you go into design view of the replicated table after the fail over and set the identity option on (just type in yes for that column for the identity option), click change script and have a look at the DDL that EM uses. You can then copy this DDL over to QA and make any appropriate changes or have EM run the script.

HTH,

Tara
Go to Top of Page

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2003-05-02 : 13:59:19
Just run the SQL Profiler and use EM to make the change you'll see all the code it takes to do this task.

Something like


set implicit_transactions on SET TEXTSIZE 2147483647
go
BEGIN TRANSACTION

go
EXECUTE sp_MSobjectprivs N'dbo.TableID2'
go
select xp.name, cast(xp.[value] as nvarchar(4000)), cast(SQL_VARIANT_PROPERTY(xp.[value], 'BaseType') as nvarchar(256)), cast(SQL_VARIANT_PROPERTY(xp.[value], 'MaxLength') as int), cast(SQL_VARIANT_PROPERTY(xp.[value], 'Precision') as int), cast(SQL_VARIANT_PROPERTY(xp.[value], 'Scale') as int)from ::fn_listextendedproperty(NULL, N'user', N'dbo', N'table', N'TableID2', NULL, NULL) xp where xp.name not in (N'MS_Description', N'MS_Filter', N'MS_OrderBy', N'MS_SubdatasheetName', N'MS_LinkChildFields', N'MS_LinkMasterFields', N'MS_SubdatasheetHeight', N'MS_SubdatasheetExpanded')
go
declare @P1 int
set @P1=180150012
declare @P2 int
set @P2=8
declare @P3 int
set @P3=1
declare @P4 int
set @P4=0
exec sp_cursoropen @P1 output, N'select xp.name, cast(xp.[value] as nvarchar(4000)), cast(SQL_VARIANT_PROPERTY(xp.[value], ''BaseType'') as nvarchar(256)), cast(SQL_VARIANT_PROPERTY(xp.[value], ''MaxLength'') as int), cast(SQL_VARIANT_PROPERTY(xp.[value], ''Precision'') as int), cast(SQL_VARIANT_PROPERTY(xp.[value], ''Scale'') as int)from ::fn_listextendedproperty(NULL, N''user'', N''dbo'', N''table'', N''TableID2'', N''column'', N''ID'') xp where xp.name not in (N''MS_Description'', N''MS_Format'', N''MS_InputMask'', N''MS_NumberOfDecimals'', N''MS_AllowBlanks'', N''MS_Caption'', N''MS_DisplayControl'', N''MS_RowSourceType'', N''MS_RowSource'', N''MS_BoundColumn'', N''MS_ColumnCount'', N''MS_ColumnHeads'', N''MS_ColumnWidths'', N''MS_ListRows'', N''MS_ListWidth'', N''MS_LimitToList'') ', @P2 output, @P3 output, @P4 output
select @P1, @P2, @P3, @P4
go
exec sp_cursorfetch 180150012, 2, 5, 5
go
declare @P1 int
set @P1=180150013
declare @P2 int
set @P2=8
declare @P3 int
set @P3=1
declare @P4 int
set @P4=0
exec sp_cursoropen @P1 output, N'select xp.name, cast(xp.[value] as nvarchar(4000)), cast(SQL_VARIANT_PROPERTY(xp.[value], ''BaseType'') as nvarchar(256)), cast(SQL_VARIANT_PROPERTY(xp.[value], ''MaxLength'') as int), cast(SQL_VARIANT_PROPERTY(xp.[value], ''Precision'') as int), cast(SQL_VARIANT_PROPERTY(xp.[value], ''Scale'') as int)from ::fn_listextendedproperty(NULL, N''user'', N''dbo'', N''table'', N''TableID2'', N''constraint'', N''PK_TableID2'') xp where xp.name not in (N''MS_ConstraintText'') ', @P2 output, @P3 output, @P4 output
select @P1, @P2, @P3, @P4
go
exec sp_cursorfetch 180150013, 2, 5, 5
go
CREATE TABLE dbo.Tmp_TableID2
(
ID int NOT NULL IDENTITY (1, 1)
) ON [PRIMARY]

go
SET IDENTITY_INSERT dbo.Tmp_TableID2 ON

go
IF EXISTS(SELECT * FROM dbo.TableID2)
EXEC('INSERT INTO dbo.Tmp_TableID2 (ID)
SELECT ID FROM dbo.TableID2 TABLOCKX')

go
SET IDENTITY_INSERT dbo.Tmp_TableID2 OFF

go
DROP TABLE dbo.TableID2

go
declare @P1 int
set @P1=0
declare @P2 int
set @P2=16388
declare @P3 int
set @P3=8193
declare @P4 int
set @P4=0
exec sp_cursoropen @P1 output, N'EXECUTE sp_rename N''dbo.Tmp_TableID2'', N''TableID2'', ''OBJECT''
', @P2 output, @P3 output, @P4 output
select @P1, @P2, @P3, @P4
go
ALTER TABLE dbo.TableID2 ADD CONSTRAINT
PK_TableID2 PRIMARY KEY CLUSTERED
(
ID
) ON [PRIMARY]


go
COMMIT


Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-05-02 : 14:02:06
Or make the change in EM and click save change script, which is much easier and faster than setting up SQL Profiler.

Tara
Go to Top of Page

chadmat
The Chadinator

1974 Posts

Posted - 2003-05-02 : 23:26:50
Just to add my 2 cents. Since you already have the system set up, you probably don't care, but Replication is not intended to be used as a failover/High availability solution. There are several other options that are intended for that use (Clustering/Log Shipping).

-Chad

http://www.clrsoft.com

Software built for the Common Language Runtime.
Go to Top of Page
   

- Advertisement -