Comparteix a través de


Escape SQL Server identifiers

You can often use the back-tick escape character (`) to escape characters allowed in SQL Server delimited identifiers but not Windows PowerShell path names. Some characters, however, cannot be escaped. For example, you can't 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 SqlServer module is the current PowerShell module to use.

The SQLPS module is included with the SQL Server installation (for backward compatibility) but is no longer updated.

The SqlServer module contains updated versions of the cmdlets in SQLPS and includes new cmdlets to support the latest SQL features.

Install the SqlServer module from the PowerShell Gallery.

For more information, visit 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