SQL Stuff

Change All Database Owners to SA

Here’s some quick SQL logic to change all the database owners to ‘sa’.

declare	@change_dbowner varchar(max)
set @change_dbowner = ''
select	@change_dbowner = @change_dbowner +
'use [' + name + '];'	+ char(10)
+'exec sp_changedbowner ''sa'''	+ char(10)
from	sys.databases where database_id > 4
order by db_name(database_id) asc
--select	(@change_dbowner) for xml path(''), type
exec	(@change_dbowner)
Advertisements

Categories: SQL Stuff

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s