sqlcmd provides a means for utilizing variables within
sqlcmd input files or scripts. These scripting variables can be assigned as
sqlcmd parameters or set within the
sqlcmd script. To illustrate the use of scripting variables, let’s change our previous backup example so that the database that will be backed up is passed as a variable. A new input file named
c:\BackupDatabase.sql should be created, and it should contain the following command:
BACKUP DATABASE $(DatabaseToBackup) TO DISK = 'c:\$(DatabaseToBackup).bak'
The variable in the preceding example is named
DatabaseToBackup. Scripting variables are referenced using the
$( ) designators. These variables are resolved at the ...