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'

1 comment:
Write comments
  1. I feel satisfied to read your blog, you have been delivering a useful & unique information to our vision even you have explained the concept as deep clean without having any uncertainty, keep blogging. SQL server dba Online Training


Please do not enter spam links


More Services