-
Notifications
You must be signed in to change notification settings - Fork 0
/
55_Mark_Not_For_Replication_On_Subscriber.sql
59 lines (47 loc) · 1.19 KB
/
55_Mark_Not_For_Replication_On_Subscriber.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
DECLARE
@PrintMessage varchar(1000)
,@PreviousTimestamp datetime
SELECT
@PrintMessage = ''
,@PreviousTimestamp = getdate()
DECLARE @SchemaName SYSNAME
,@tableName SYSNAME
,@columnName SYSNAME
,@query NVARCHAR(4000)
DECLARE cur CURSOR
FOR
SELECT QUOTENAME(SCHEMA_NAME(t.schema_id)) AS SchemaName
,QUOTENAME(t.NAME) AS TableName
,c.NAME AS ColumnName
--,c.object_id AS ObjectID
--,c.is_not_for_replication
,'EXEC sys.sp_identitycolumnforreplication ' + cast(c.object_id AS VARCHAR(20))
+ ', 1 ;' AS CommandTORun_SetIdendityNOTForReplication
FROM sys.identity_columns AS c
INNER JOIN sys.tables AS t ON t.[object_id] = c.[object_id]
WHERE c.is_identity = 1
AND c.is_not_for_replication = 0
AND t.name IN ('Table1'
,'Table2'
,'Table3')
OPEN cur
FETCH NEXT
FROM cur
INTO @SchemaName
,@tableName
,@columnName
,@query
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT 'Setting Not_For_Replication property to 1 for (Schema.Table.Column): '
+ @SchemaName + '.' + @tableName + '.' + @columnName
EXEC (@query)
FETCH NEXT
FROM cur
INTO @SchemaName
,@tableName
,@columnName
,@query
END
CLOSE cur
DEALLOCATE cur