Advertisements
Following is the DBA script which generally used for most cases the action needed for all the databases like migration, upgrade etc.
Change the database recovery model and set to single_user mode.
Backup of all databases.
-- Dynamic SQL select 'alter database ['+name+'] set single_user with rollback immediate' , * from sys.databases where database_id not in (1,2,3,4)-- exclude system DBs select 'alter database ['+name+'] set multi_usere' , * from sys.databases where database_id not in (1,2,3,4)-- exclude system DBs select 'alter database ['+name+'] set recovery simple' , * from sys.databases where database_id not in (1,2,3,4)-- exclude system DBs select 'backup database ['+name+'] to disk = ''B:\SQL_backup\'+name+'_full.bak''' , * from sys.databases where database_id not in (1,2,3,4)-- exclude system DBs
We can write anything in the single quote and the separator is + symbol and can use any system objects like sys.databases and sys.objects.
This will be helpful for junior DBAs.