Skip to content

Instantly share code, notes, and snippets.

@Otterpohl
Created May 13, 2022 16:22

Revisions

  1. Otterpohl created this gist May 13, 2022.
    5 changes: 5 additions & 0 deletions Set-DatabaseOwnerToSA.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    SELECT 'ALTER AUTHORIZATION ON DATABASE::' + QUOTENAME(d.[name]) + ' to sa'
    FROM [sys].[databases] d
    INNER JOIN [sys].[server_principals] s ON s.sid = d.owner_sid
    WHERE d.[name] NOT IN ('master','msdb','model','tempdb')
    AND s.[name] <> 'sa'