There are lots of little tricks that you can use to become more proficient, and efficient, at writing T-SQL. Here’s a short one that might be more for administrators, but I think for developers it’s very handy as well.
SQL Server tools have included templates for years. I first started using them in Query Analyzer with SQL Server 2000. The tools have changed, but we still have templates in Management Studio (SSMS). We can access the templates by exposing the Template Browser from the View menu (as shown below).
We can also use the CTRL+ALT+T shortcut. Either of these will give us a tab on the right side of our SSMS main window, opposite the Object Explorer, as shown below.
Like all the windows in SSMS, I can detach this, move it, auto hide, etc.
Each of these folders contains a series of default scripts that are installed with the tools. For example, I can look at the Backup folder and see three scripts in there. I can grab one of them with a left click and "drag" it to the query window and the script will appear in the query window as I’ve shown here.
A CTRL+Shift+M will give me the parameters in the script, which I can replace with my own values (or accept the defaults).
Many of these are generic, but they are useful. I’d encourage you to take a look at them and use them when you can.
You can customize these, but that’s for another post.
Filed under: Blog Tagged: syndicated, T-SQL
![]()