Below script can be used to change DB Owner details of all databases in SQL Server. This script can be modified as per owner change requirement.

declare​​ @changedbowner​​ varchar(255)

set​​ @changedbowner​​ =​​ ''

select​​ @changedbowner​​ =@changedbowner​​ +

'use ['​​ +​​ db.name+']; exec sp_changedbowner ['​​ +​​ db.name+'_dbo]'​​ 

from​​ sys.databases​​ db​​ left​​ join​​ sys.server_principals​​ sp

on​​ db.owner_sid=sp.sid​​ where​​ database_id​​ >​​ 4​​ -- excluding system databases

print​​ (@changedbowner)​​ -- will display auto generated script

--exec (@changedbowner) -- will change db owner

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.