Altering TSQL to get codes where ever possible;
#Generate quick commands
#SQL code Trick
This is a Quick trick that I recently learned from one of my teammate, that I would like to share with you all.
We must have come across a lot of situation where we need to run multiple commands to get our work done, But we have to repeat the task multiple times to complete the task.
To simplify we will learn how to generate the queries from command itself that gives you upper hand on the task and smart working advantage.
Scenario:
We had to alter all the databases to simple recovery model from full since these were restored from the PROD server all were in full with agreed SLA.
So instead of running and altering the databases command we generated it with a trick.
Command;
select'alter database '+name+' set recovery simple',recovery_model_desc,*from sys.databases where database_id>4
/*-- Database_id>4 is to select only the user databases. --*/
Result :
alter database ReportServer set recovery simple
alter database ReportServerTempDB set recovery simple
Do let me know if this is useful to you. Comment and suggest topics for blog you wish to see.
Share with your DBA friends and help them work smartly.
Knowledge Shared by: Pramod Thikekar: SQL DBA with great 5 yrs of great experience.
No comments:
Post a Comment