Important Scripts and Procedures for SQL DBA
Imporant Scripts & Procedures for SQL DBA Daily help for DBA task. To know logins - sp_helpuser ----------------------------------------- To shrink tempdb dbcc freeproccache() Shrink db ----------------------------------------------------------------------------------- To script out logins - sp_help_revlogin ------------------------------------------------------------------------------------ To change db owner - sp_changedbowner 'sa' ------------------------------------------------------------------------------------- Step 1: Check the databases that does not have sa account as the owner SELECT name AS DBName, suser_sname(owner_sid) AS DBOwner FROM sys.databases WHERE suser_sname(owner_sid) <> 'sa' Step 2: Generate the scripts to make sa account as owner for all the databases SELECT 'ALTER AUTHORIZATION ON DATABASE::' + QUOTENAME(name) + ' TO [sa];' from sys.databases where name not in ('master', 'mode...