Created
October 2, 2013 15:22
-
-
Save duncanmcdougall/6795466 to your computer and use it in GitHub Desktop.
Change all database owners on a SQL Server to another on a server in one swoop. Scary but it works.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE master | |
GO | |
DECLARE @sqlBase nvarchar(300) = 'ALTER AUTHORIZATION ON database::XXXXX TO sa'+char(13)+char(10) | |
DECLARE @sql nvarchar(max)='' | |
SELECT @sql = @sql + REPLACE(@sqlBase,'XXXXX',name) from sys.databases | |
where name not in ('master', 'model', 'tempdb', 'distribution', 'msdb') | |
EXECUTE(@sql) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment