The following sql logic will simply change all database owners to ‘sa’. It’s a tried and true method. Will affect all databases excluding the system databases. Additionally; the final script will confirm all database owners have been changed to ‘sa’. Anyone can do this, but thought I would post anyway to save you a few keystrokes.
declare @change_db_owners varchar(max) set @change_db_owners = '' select @change_db_owners = @change_db_owners + 'exec [' + name + ']..sp_changedbowner ''sa'';' + char(10) from sys.databases where database_id > 4 exec (@change_db_owners) --for xml path(''), type select 'database' = upper(name) , 'owner' = suser_sname(owner_sid) from sys.databases where database_id > 4 order by name asc
Categories: Agent Jobs, Alerts, Automations, Backup & Restore, Command Prompt, Database Mail, Database Mirroring, ELI5, Error Solutions, Featured, Folder System, Forensics & Auditing, High Availability, Long Scripts, Management Studio, Mirroring, Notification, Powershell, Quick Fix, Scripts, Security, Short Scripts, SQL Stuff, Top, TSQL, Work Arounds