Add NOT FOR REPLICATION to the column

If you had a table defined something like

CREATE TABLE [MyTable](
	[IdCol] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY

)

and later you want to add this table in the replication but you want that replication agent treats it differently when performs an insert operation. With NOT FOR REPLICATION option you can generaly control if foreign keys, check constraints, triggers and identity colums are enforced on the subscriber or not.

Updating column from previos definition to not enforce IDENTITY constraint to subscriber can be done with

ALTER TABLE [MyTable] ALTER COLUMN [MyCol] ADD NOT FOR REPLICATION

After this update table definition will looks like

CREATE TABLE [MyTable](
	[IdCol] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL PRIMARY KEY

)

Leave a Reply

Your email address will not be published. Required fields are marked *