VanillaGranilla icon

change DB owners to sa

VanillaGranilla | PRO | 03/27/18 05:01:13 PM UTC | 0 ⭐ | 256 👁️ | Never ⏰ | []
T-SQL |

310 B

|

None

|

0 👍

/

0 👎

select [name] as [dbname],
    SUSER_SNAME([owner_sid]) AS [currentowner],
    N'ALTER AUTHORIZATION ON DATABASE::'
    + QUOTENAME([name]) + ' TO '
    + QUOTENAME((SELECT [name] FROM sys.sql_logins WHERE sid = 0x01)) AS scriptoutput
from sys.databases
where database_id > 4
    AND owner_sid <> 0x01
    AND state_desc = 'ONLINE'

Comments