Saving and Reusing Your Custom Queries as Template Using Template Explorer in SQL Server 2008


Introduction

In this article I will show you how to save your custom queries as a template and reuse the queries instead of saving as a file.

Advantages

  1. We have a folder structure.
  2. Easy to Navigate.
  3. Very flexible and also handy to use.
  4. It is stored within the SQL so we can reuse easily.

There are many uses of the template explorer in the view menu. A pictorial representation helps more than textual. So here I have described all the steps in the pictorial
form.

Shortcut Key of Template Explorer

CTRL + ALT + T

Step 1: Click the View menu and select Template Explorer.

1.jpg

Step 2: Where the Template Explorer is located within the SQL.

2.jpg

Step 3: List of Options is available when right-clicking folder.

3.jpg

Step 4: Shows the list of templates available as default.

4.jpg

Step 5: How to create folder for template file.

5.jpg

After adding folder, note we can also add Sub folder too.

6.jpg

Step 6: How to rename the folder.

7.jpg

Step 7: How to Add template file within the created folder.

Template file takes the extension .SQL

8.jpg

And after adding the template file:

9.jpg

Step 8: If you need to modify then you need to right-click the template file and click EDIT and then change the query. This also applies to adding extra queries to the existing Template file.

Note: If you double-click the file and modify something and try to save it, it will ask wheteher you want to save as.

Always use EDIT in the Template file to save the changes.

10.jpg

Step 9: After clicking EDIT by right-clicking on the template file, we can add or modify the queries.

11.jpg

After editing the template, just use the shortcut CTRL + S to save the modification within the template file.

Step 10: Adding template file within the sub folder.

12.jpg

Then the next image will be.

Step 11: How to search template folder or template file within the selected folder.

14.jpg

The search result will be.

15.jpg

Step 12: Copying, cutting and also you can delete both template folder and template file.

16.jpg

Conclusion

Thus I have explained how to save your custom queries and reuse it in SQL Server.
Thanks for reading this article.

Up Next
    Ebook Download
    View all
    Learn
    View all