Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement