From 93e4bbc7b57be79f697ee5df2e8a691f59f43f0c Mon Sep 17 00:00:00 2001 From: Alexey Bochkov Date: Mon, 4 Feb 2019 15:57:52 -0800 Subject: [PATCH] Update mark identity NOT FOR REPLICATION.sql --- .../mark identity NOT FOR REPLICATION.sql | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/QueryTemplates/Common Scripts/mark identity NOT FOR REPLICATION.sql b/QueryTemplates/Common Scripts/mark identity NOT FOR REPLICATION.sql index 5aec674..6183f8d 100644 --- a/QueryTemplates/Common Scripts/mark identity NOT FOR REPLICATION.sql +++ b/QueryTemplates/Common Scripts/mark identity NOT FOR REPLICATION.sql @@ -2,3 +2,22 @@ EXEC sp_msforeachtable @command1 = ' declare @int int set @int =object_id("?") EXEC sys.sp_identitycolumnforreplication @int, 1' + + + +--smarter way to do it +SELECT + s.name AS schemaName, + o.name AS tableName, + ic.name AS columnName, +'declare @int int +set @int =object_id(''[' + s.name + '].[' + o.name + ']'') +EXEC sys.sp_identitycolumnforreplication @int, 1; +GO' AS command +FROM sys.identity_columns ic + INNER JOIN sys.tables o + ON ic.object_id = o.object_id + INNER JOIN sys.schemas s + ON o.schema_id = s.schema_id +WHERE ic.is_not_for_replication = 0 + AND o.is_ms_shipped = 0