Just wondering if there is some T-SQL that will allow me to assign a user as the owner of a SQL Server database if it doesn't already have an owner?
We're getting the following error out in customer setups:
Cannot execute as the database principal because the principal "dbo" does not exist, this type of principal cannot be impersonated, or you do not have permission
This is because the database doesn't have an assigned owner. So we want to get a script to integrate into the product that will check if there is an assigned owner and if not run something like:
EXEC sp_changedbowner [current]