VanillaGranilla

change DB owners to sa

Mar 27th, 2018
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.31 KB | None | 0 0
  1. select [name] as [dbname],
  2.     SUSER_SNAME([owner_sid]) AS [currentowner],
  3.     N'ALTER AUTHORIZATION ON DATABASE::'
  4.     + QUOTENAME([name]) + ' TO '
  5.     + QUOTENAME((SELECT [name] FROM sys.sql_logins WHERE sid = 0x01)) AS scriptoutput
  6. from sys.databases
  7. where database_id > 4
  8.     AND owner_sid <> 0x01
  9.     AND state_desc = 'ONLINE'
Advertisement
Add Comment
Please, Sign In to add comment