Using Templates in SQL Query Analyzer

SQL Query Analyzer Help

SQL Query Analyzer Help

Using Templates in SQL Query Analyzer

Templates are boilerplate files containing SQL scripts that help you create objects in the database. Microsoft® SQL Server™ 2000 provides a variety of templates in the Templates\SQL Query Analyzer directory. Among the templates provided are those that create databases, tables, views, indexes, stored procedures, triggers, statistics, and functions. In addition, there are templates that help you to manage extended properties, linked servers, logins, roles, and users, and to declare and use cursors.

The template scripts provided with SQL Query Analyzer contain parameters to help you customize the code. Template parameter definitions use this format:

<parameter_name, data_type, value>

where

  • parameter_name is the name of the parameter in the script.

  • data_type is the data type of the parameter.

  • value is the value that is to replace every occurrence of the parameter in the script.

Use the Replace Template Parameters dialog box to insert values into the script.

Note  You can use the Replace Template Parameters dialog box to specify values any time a parameter definition is used in code. For example, when you execute a function from Object Browser, the function that is written to the Editor pane contains parameter definitions for any arguments in the function. You can, therefore, use the Replace Template Parameters dialog box to specify argument values.

To use a template

  1. Open a Query window.

  2. Click Insert Template on the toolbar.

  3. In the Insert Template dialog box, specify the template to open. By default, template files have the extension .tql.

  4. When the template is displayed in the Editor pane, select Replace Template Parameters from the Edit menu.

  5. In the Replace Template Parameters dialog box, specify values for the parameters.

  6. To insert the specified values into the script in the Editor pane, click Replace All.

  7. Save the file under a different name.