Escape SQL Server Identifiers

THIS TOPIC APPLIES TO: yesSQL ServeryesAzure SQL DatabaseyesAzure SQL Data Warehouse yesParallel Data Warehouse

You can often use the back-tick escape character (`) to escape characters that are allowed in SQL Server delimited identifiers but not Windows PowerShell path names. Some characters, however, cannot be escaped. For example, you cannot escape the colon character (:) in Windows PowerShell. Identifiers with that character must be encoded. Encoding is more reliable than escaping because encoding works for all characters.

Note

There are two SQL Server PowerShell modules; SqlServer and SQLPS. The SQLPS module is included with the SQL Server installation (for backwards compatibility), but is no longer being updated. The most up-to-date PowerShell module is the SqlServer module. The SqlServer module contains updated versions of the cmdlets in SQLPS, and also includes new cmdlets to support the latest SQL features. Previous versions of the SqlServer module were included with SQL Server Management Studio (SSMS), but only with the 16.x versions of SSMS. To use PowerShell with SSMS 17.0 and later, the SqlServer module must be installed from the PowerShell Gallery. To install the SqlServer module, see Install SQL Server PowerShell.

The back-tick character (`) is usually on the key in the upper left of the keyboard, under the ESC key.

Examples

This is an example of escaping a # character:

cd SQLSERVER:\SQL\MyComputer\MyInstance\MyDatabase\MySchema\`#MyTempTable  

This is an example of escaping the parenthesis when specifying (local) as a computer name:

Set-Location SQLSERVER:\SQL\`(local`)\DEFAULT  

See Also

SQL Server Identifiers in PowerShell
SQL Server PowerShell Provider
SQL Server PowerShell