I have created the following SQL code to create a script to change the owner of a MS SQL Server database:
SQL Code:
/*Change Owners of a table:*/ DECLARE @OldOwner CHAR(25) DECLARE @NewOwner CHAR(25) SET @OldOwner ='dbo' SET @NewOwner = 'ADM' SELECT 'exec sp_changeobjectowner ' + CHAR(39) + RTRIM(LTRIM(@OldOwner)) + '.' + _ Name + CHAR(39) +',' + CHAR(39)+ RTRIM(LTRIM(@NewOwner)) + CHAR(39) Owner_Change_Script FROM sysobjects WHERE xtype = 'U' AND UID = 5 ORDER by Name
This code outputs the following:
SQL Code:
exec sp_changeobjectowner 'dbo.CLASSES','ADM' exec sp_changeobjectowner 'dbo.CAUSES','ADM' exec sp_changeobjectowner 'dbo.LEVEL','ADM' exec sp_changeobjectowner 'dbo.ACCIDENTS','ADM' exec sp_changeobjectowner 'dbo.ACTIONS','ADM'
But I want the Script to insert a 'Go' in between each exec statement like this:
SQL Code:
exec sp_changeobjectowner 'dbo.CLASSES','ADM' GO exec sp_changeobjectowner 'dbo.CAUSES','ADM' GO exec sp_changeobjectowner 'dbo.LEVEL','ADM' GO exec sp_changeobjectowner 'dbo.ACCIDENTS','ADM' GO exec sp_changeobjectowner 'dbo.ACTIONS','ADM' GO
But for the life of me I can't seem to figure it out. Any ideas how I can go about doing this??? The databases I have to convert have hundreds and hundreds of tables and when it throws an error I want to be able to click on the error and be brought to the line that threw the error.
Thanks!




Reply With Quote