In a production SQL Server environment the database owner is usually carefully maintained and consistent. This isn’t always the case on development servers or on servers that you may inherit from other organizations. This script was written originally for a development environment with multiple database owners – one of the developers left the project and their user account needed to be removed.
If you just need to change a single database owner use the SQL command (change the database name and owner of course):
ALTER AUTHORIZATION ON DATABASE::[AdventureWorks2012] TO [sa]
If you need to change the owner on multiple databases or if you just want to see the current owners on the databases you can use the script referenced here – ADMIN.Database.Owners.Change.
Check out the SQL Server BOL entry on ALTER AUTHORIZATION to see the security requirements and other restrictions.
Be sure to check out our other SQL Server scripts here – I-Tech SQL Server Scripts.