Scripting SQL Server Database Owners

In a new environment, I noted that not all the SQL Server databases are owned by the 'sa 'account. I know this isn't a good practice, but in addition to that reason, some of the databases have to be owned by particular accounts.

there is a way to script this so that we can set the proper owners for databases in case of disaster recovery.

SELECT AS 'Database', AS 'Owner'
FROM sys.databases D
  JOIN sys.server_principals P
    ON D.owner_sid = P.sid
       --where <> 'sa'

No comments:
Write comments

Please do not enter spam links

Meet US


More Services