Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Declare @Table nvarchar(50), @script nvarchar(100)
- DECLARE cur CURSOR FORWARD_ONLY READ_ONLY LOCAL FOR
- 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
- OPEN cur
- FETCH NEXT FROM cur INTO @Table
- WHILE @@FETCH_STATUS = 0 BEGIN
- -- The sql command to alter a Table and add Identity to it, you can change ID by any column in your tables
- set @script = 'Alter Table '+ @Table +' ADD ID INT IDENTITY'
- EXEC sp_executesql @script
- FETCH NEXT FROM cur INTO @Table
- END
- CLOSE cur
- DEALLOCATE cur
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement