|
1 | 1 | --- |
2 | | -title: "Encode and Decode SQL Server Identifiers | Microsoft Docs" |
| 2 | +title: Encode and Decode SQL Server Identifiers |
3 | 3 | description: Some characters that can appear in SQL Server-delimited identifiers are not supported in Windows PowerShell paths. Learn how to include them by representing them with their hexadecimal values. |
4 | | -ms.custom: "" |
5 | | -ms.date: "03/14/2017" |
6 | 4 | ms.prod: sql |
7 | | -ms.reviewer: "" |
8 | 5 | ms.technology: sql-server-powershell |
9 | 6 | ms.topic: conceptual |
10 | 7 | ms.assetid: bb9fe0d3-e432-42d3-b324-64dc908b544a |
11 | 8 | author: markingmyname |
12 | 9 | ms.author: maghan |
| 10 | +ms.reviewer: matteot, drskwier |
| 11 | +ms.custom: "" |
| 12 | +ms.date: 10/14/2020 |
13 | 13 | --- |
| 14 | + |
14 | 15 | # Encode and Decode SQL Server Identifiers |
| 16 | + |
15 | 17 | [!INCLUDE[SQL Server Azure SQL Database Synapse Analytics PDW ](../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw.md)] |
16 | 18 |
|
17 | | -SQL Server-delimited identifiers sometimes contain characters not supported in Windows PowerShell paths. These characters can be specified by encoding their hexadecimal values. |
18 | | - |
19 | | -> [!NOTE] |
20 | | -> 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. |
21 | | -> 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. |
22 | | -> To install the **SqlServer** module, see [Install SQL Server PowerShell](download-sql-server-ps-module.md). |
23 | | - |
24 | | - |
25 | | -Characters that are not supported in Windows PowerShell path names can be represented, or encoded, as the "%" character followed by the hexadecimal value for the bit pattern that represents the character, as in "**%**xx". Encoding can always be used to handle characters that are not supported in Windows PowerShell paths. |
26 | | - |
27 | | - The **Encode-SqlName** cmdlet takes as input a [!INCLUDE[ssNoVersion](../includes/ssnoversion-md.md)] identifier. It outputs a string with all the characters that are not supported by the Windows PowerShell language encoded with "%xx". The **Decode-SqlName** cmdlet takes as input an encoded [!INCLUDE[ssNoVersion](../includes/ssnoversion-md.md)] identifier and returns the original identifier. |
28 | | - |
29 | | -## <a name="LimitationsRestrictions"></a> Limitations and Restrictions |
30 | | - The **Encode-Sqlname** and **Decode-Sqlname** cmdlets only encode or decode the characters that are allowed in SQL Server-delimited identifiers, but are not supported in PowerShell paths. The following are the characters encoded by **Encode-SqlName** and decoded by **Decode-SqlName**: |
31 | | - |
32 | | -||||||||||||| |
33 | | -|-|-|-|-|-|-|-|-|-|-|-|-| |
| 19 | +SQL Server-delimited identifiers sometimes contain characters not supported in Windows PowerShell paths. These characters can be specified by encoding their hexadecimal values. |
| 20 | + |
| 21 | +[!INCLUDE [sql-server-powershell-version](../includes/sql-server-powershell-version.md)] |
| 22 | + |
| 23 | +Characters that are not supported in Windows PowerShell path names can be represented, or encoded, as the "%" character followed by the hexadecimal value for the bit pattern that represents the character, as in "**%**xx". Encoding can always be used to handle characters that are not supported in Windows PowerShell paths. |
| 24 | + |
| 25 | +The **Encode-SqlName** cmdlet takes as input a [!INCLUDE[ssNoVersion](../includes/ssnoversion-md.md)] identifier. It outputs a string with all the characters that are not supported by the Windows PowerShell language encoded with "%xx". The **Decode-SqlName** cmdlet takes as input an encoded [!INCLUDE[ssNoVersion](../includes/ssnoversion-md.md)] identifier and returns the original identifier. |
| 26 | + |
| 27 | +## Limitations and Restrictions |
| 28 | + |
| 29 | +The **Encode-Sqlname** and **Decode-Sqlname** cmdlets only encode or decode the characters that are allowed in SQL Server-delimited identifiers, but are not supported in PowerShell paths. The following are the characters encoded by **Encode-SqlName** and decoded by **Decode-SqlName**: |
| 30 | + |
| 31 | +||||||||||||| |
| 32 | +|-|-|-|-|-|-|-|-|-|-|-|-| |
34 | 33 | |**Character**|\ |/|:|%|\<|>|*|?|[|]||| |
35 | | -|**Hexadecimal Encoding**|%5C|%2F|%3A|%25|%3C|%3E|%2A|%3F|%5B|%5D|%7C| |
36 | | - |
37 | | -## <a name="EncodeIdent"></a> Encoding an Identifier |
38 | | - **To encode a SQL Server identifier in a PowerShell path** |
39 | | - |
40 | | -- Use one of two methods to encode a SQL Server identifier: |
41 | | - |
42 | | - - Specify the hexadecimal code for the unsupported character using the syntax %XX, where XX is the hexadecimal code. |
43 | | - |
44 | | - - Pass the identifier as a quoted string to the **Encode-Sqlname** cmdlet |
45 | | - |
46 | | -### Examples (Encoding) |
47 | | - This example specifies the encoded version of the ":" character (%3A): |
48 | | - |
49 | | -``` |
50 | | -Set-Location Table%3ATest |
51 | | -``` |
52 | | - |
53 | | - Alternatively, you can use **Encode-SqlName** to build a name supported by Windows PowerShell: |
54 | | - |
55 | | -``` |
56 | | -Set-Location (Encode-SqlName "Table:Test") |
57 | | -``` |
58 | | - |
59 | | -## <a name="DecodeIdent"></a> Decoding an Identifier |
60 | | - **To decode a SQL Server identifier from a PowerShell path** |
61 | | - |
62 | | - Use the **Decode-Sqlname** cmdlet to replace the hexadecimal encodings with the characters represented by the encoding. |
63 | | - |
64 | | -### Examples (Decoding) |
65 | | - This example returns "Table:Test": |
66 | | - |
67 | | -``` |
68 | | -Decode-SqlName "Table%3ATest" |
69 | | -``` |
70 | | - |
71 | | -## See Also |
72 | | - [SQL Server Identifiers in PowerShell](sql-server-identifiers-in-powershell.md) |
73 | | - [SQL Server PowerShell Provider](sql-server-powershell-provider.md) |
74 | | - [SQL Server PowerShell](sql-server-powershell.md) |
75 | | - |
76 | | - |
| 34 | +|**Hexadecimal Encoding**|%5C|%2F|%3A|%25|%3C|%3E|%2A|%3F|%5B|%5D|%7C| |
| 35 | + |
| 36 | +## Encoding an Identifier |
| 37 | + |
| 38 | +### To encode a SQL Server identifier in a PowerShell path |
| 39 | + |
| 40 | +- Use one of two methods to encode a SQL Server identifier: |
| 41 | + - Specify the hexadecimal code for the unsupported character using the syntax %XX, where XX is the hexadecimal code. |
| 42 | + - Pass the identifier as a quoted string to the **Encode-Sqlname** cmdlet |
| 43 | + |
| 44 | +### Examples (Encoding) |
| 45 | + |
| 46 | +This example specifies the encoded version of the ":" character (%3A): |
| 47 | + |
| 48 | +```powershell |
| 49 | +Set-Location Table%3ATest |
| 50 | +``` |
| 51 | + |
| 52 | +Alternatively, you can use **Encode-SqlName** to build a name supported by Windows PowerShell: |
| 53 | + |
| 54 | +```powershell |
| 55 | +Set-Location (Encode-SqlName "Table:Test") |
| 56 | +``` |
| 57 | + |
| 58 | +## Decoding an Identifier |
| 59 | + |
| 60 | +### To decode a SQL Server identifier from a PowerShell path |
| 61 | + |
| 62 | +Use the **Decode-Sqlname** cmdlet to replace the hexadecimal encodings with the characters represented by the encoding. |
| 63 | + |
| 64 | +### Examples (Decoding) |
| 65 | + |
| 66 | +This example returns "Table:Test": |
| 67 | + |
| 68 | +```powershell |
| 69 | +Decode-SqlName "Table%3ATest" |
| 70 | +``` |
| 71 | + |
| 72 | +## See Also |
| 73 | + |
| 74 | +- [SQL Server Identifiers in PowerShell](sql-server-identifiers-in-powershell.md) |
| 75 | +- [SQL Server PowerShell Provider](sql-server-powershell-provider.md) |
| 76 | +- [SQL Server PowerShell](sql-server-powershell.md) |
0 commit comments