If you’ve ever used the Template Explorer Ctrl+Alt+T in SQL Server Management Studio (SSMS), then you may already be familiar with the concept of parameterized in SSMS. You can use Ctrl+Shift+M to replace parameterized values in the template with your own values. You can also create your own parameterized values in SQL scripts that you may have.

The parameters are enclosed in angle brackets and have three values like so.

<parameter_name, data_type, default_value>

Let’s say you wanted to create sandbox databases for various individuals to have their own copy.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
/*
This script is parameterized. Use Ctrl+Shift+M to get the dialog box to set the parameter values.
*/
use master
go

create database [Sandbox_<sandbox_database_name, varchar(30), dev01>];
go

use [Sandbox_<sandbox_database_name, varchar(30), dev01>]
go

create user [<username, sysname, username>] with default schema dbo;

grant execute on schema::[dbo] to [<username, sysname, username>];