daily pastebin goal
75%
SHARE
TWEET

Untitled

a guest Jul 17th, 2017 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Declare @Table nvarchar(50), @script nvarchar(100)
  2.  
  3.     DECLARE cur CURSOR FORWARD_ONLY READ_ONLY LOCAL FOR
  4.         SELECT TABLE_SCHEMA + '.' + TABLE_NAME as 'Table' FROM INFORMATION_SCHEMA.TABLES where TABLE_NAME not in ('sysdiagrams') -- You can exclude any table from this process by adding it on the where statement
  5.  
  6.     OPEN cur
  7.     FETCH NEXT FROM cur INTO @Table
  8.     WHILE @@FETCH_STATUS = 0 BEGIN
  9.         -- The sql command to alter a Table and add Identity to it, you can change ID by any column in your tables
  10.         set @script = 'Alter Table '+ @Table +' ADD ID INT IDENTITY'
  11.  
  12.  
  13.         EXEC sp_executesql @script
  14.  
  15.         FETCH NEXT FROM cur INTO @Table
  16.     END
  17.  
  18.     CLOSE cur
  19.     DEALLOCATE cur
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top