Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.68 KB | None | 0 0
  1. ---Disable Triggers
  2.                                         DECLARE table_cursor CURSOR
  3.                                             FOR SELECT TABLE_SCHEMA, TABLE_NAME
  4.                                                 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE <> 'VIEW'
  5.  
  6.                                         DECLARE @table_schema nvarchar(2000), @table_name nvarchar(2000)
  7.  
  8.                                         OPEN table_cursor
  9.  
  10.                                         FETCH NEXT FROM table_cursor   
  11.                                             INTO @table_schema, @table_name
  12.  
  13.                                         WHILE @@FETCH_STATUS = 0
  14.                                             BEGIN
  15.                                                 DECLARE @sql nvarchar(2000)
  16.                                                 SET @sql = 'ALTER TABLE ' + @table_schema + '.[' + @table_name + '] DISABLE TRIGGER all'
  17.                                                 PRINT @sql
  18.                                                 EXEC (@sql)
  19.                                                 FETCH NEXT FROM table_cursor   
  20.                                                     INTO @table_schema, @table_name
  21.                                             END
  22.  
  23.                                         CLOSE table_cursor
  24.                                         DEALLOCATE table_cursor
  25.  
  26.  
  27.  
  28. ---Enable Triggers
  29.                                             DECLARE table_cursor CURSOR
  30.                                                 FOR SELECT TABLE_SCHEMA, TABLE_NAME
  31.                                                     FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE <> 'VIEW'
  32.  
  33.                                             DECLARE @table_schema nvarchar(2000), @table_name nvarchar(2000)
  34.  
  35.                                             OPEN table_cursor
  36.  
  37.                                             FETCH NEXT FROM table_cursor   
  38.                                                 INTO @table_schema, @table_name
  39.  
  40.                                             WHILE @@FETCH_STATUS = 0
  41.                                                 BEGIN
  42.                                                     DECLARE @sql nvarchar(2000)
  43.                                                     SET @sql = 'ALTER TABLE ' + @table_schema + '.[' + @table_name + '] ENABLE TRIGGER all'
  44.                                                     PRINT @sql
  45.                                                     EXEC (@sql)
  46.                                                     FETCH NEXT FROM table_cursor   
  47.                                                         INTO @table_schema, @table_name
  48.                                                 END
  49.  
  50.                                             CLOSE table_cursor
  51.                                             DEALLOCATE table_cursor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement