Skip to content

Commit 2904efe

Browse files
authored
Merge pull request #16940 from pmasl/patch-882
Update constants-transact-sql.md
2 parents 59d8a59 + 907386d commit 2904efe

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

docs/t-sql/data-types/constants-transact-sql.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description: "Constants (Transact-SQL)"
33
title: "Constants (Transact-SQL) | Microsoft Docs"
44
ms.custom: ""
5-
ms.date: "07/22/2017"
5+
ms.date: "09/09/2020"
66
ms.prod: sql
77
ms.prod_service: "database-engine, sql-database, sql-data-warehouse, pdw"
88
ms.reviewer: ""
@@ -41,8 +41,11 @@ A constant, also known as a literal or a scalar value, is a symbol that represen
4141

4242
## Character string constants
4343
Character string constants are enclosed in single quotation marks and include alphanumeric characters (a-z, A-Z, and 0-9) and special characters, such as exclamation point (!), at sign (@), and number sign (#). Character string constants are assigned the default collation of the current database, unless the COLLATE clause is used to specify a collation. Character strings typed by users are evaluated through the code page of the computer and are translated to the database default code page if it is required.
44+
45+
> [!NOTE]
46+
> When a [UTF8-enabled collation](../../relational-databases/collations/collation-and-unicode-support.md#utf8) is specified using the COLLATE clause, the character string behaves like a [Unicode string](#unicode-strings).
4447
45-
If the QUOTED_IDENTIFIER option has been set OFF for a connection, character strings can also be enclosed in double quotation marks, but the Microsoft [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] Native Client Provider and ODBC driver automatically use SET QUOTED_IDENTIFIER ON. We recommend using single quotation marks.
48+
If the QUOTED_IDENTIFIER option has been set OFF for a connection, character strings can also be enclosed in double quotation marks, but the Microsoft [OLE DB Driver for SQL Server](../../connect/oledb/oledb-driver-for-sql-server.md) and [ODBC Driver for SQL Server](../../connect/odbc/download-odbc-driver-for-sql-server.md) automatically use `SET QUOTED_IDENTIFIER ON`. We recommend using single quotation marks.
4649

4750
If a character string enclosed in single quotation marks contains an embedded quotation mark, represent the embedded single quotation mark with two single quotation marks. This is not required in strings embedded in double quotation marks.
4851

@@ -58,18 +61,23 @@ The following are examples of character strings:
5861

5962
Empty strings are represented as two single quotation marks with nothing in between. In 6.x compatibility mode, an empty string is treated as a single space.
6063

61-
Character string constants support enhanced collations.
64+
Character string constants support enhanced [collations](../../relational-databases/collations/collation-and-unicode-support.md).
6265

6366
> [!NOTE]
64-
> Character constants greater than 8000 bytes are typed as **varchar(max)** data.
67+
> Character constants greater than 8000 bytes are typed as **varchar(max)** data.
6568
6669
## Unicode strings
67-
Unicode strings have a format similar to character strings but are preceded by an N identifier (N stands for National Language in the SQL-92 standard). The N prefix must be uppercase. For example, 'Michél' is a character constant while N'Michél' is a Unicode constant. Unicode constants are interpreted as Unicode data, and are not evaluated by using a code page. Unicode constants do have a collation. This collation primarily controls comparisons and case sensitivity. Unicode constants are assigned the default collation of the current database, unless the COLLATE clause is used to specify a collation. Unicode data is stored by using 2 bytes per character instead of 1 byte per character for character data. For more information, see [Collation and Unicode Support](../../relational-databases/collations/collation-and-unicode-support.md).
70+
Unicode strings have a format similar to character strings but are preceded by an N identifier (N stands for National Language in the SQL-92 standard) or specified through the use of the COLLATE clause with an [UTF8-enabled collation](../../relational-databases/collations/collation-and-unicode-support.md#utf8).
71+
72+
> [!IMPORTANT]
73+
> The N prefix must be uppercase.
74+
75+
For example, `'Michél'` is a character constant while `N'Michél'` is a Unicode constant. Unicode constants are interpreted as Unicode data, and are not evaluated by using a code page. Unicode constants do have a collation. This collation primarily controls comparisons and case sensitivity. Unicode constants are assigned the default collation of the current database, unless the COLLATE clause is used to specify a collation. Unicode data uses the variable-width encoding. For more information, see [Collation and Unicode Support](../../relational-databases/collations/collation-and-unicode-support.md#storage_differences).
6876

6977
Unicode string constants support enhanced collations.
7078

7179
> [!NOTE]
72-
> Unicode constants greater than 8000 bytes are typed as **nvarchar(max)** data.
80+
> Unicode constants greater than 8000 bytes are typed as **nvarchar(max)** data.
7381
7482
## Binary constants
7583
Binary constants have the prefix `0x` and are a string of hexadecimal numbers. They are not enclosed in quotation marks.
@@ -194,11 +202,12 @@ Signed **money** expressions:
194202
```
195203

196204
## Enhanced Collations
197-
SQL Server supports character and Unicode string constants that support enhanced collations. For more information, see the [COLLATE (Transact-SQL)](https://msdn.microsoft.com/library/4ba6b7d8-114a-4f4e-bb38-fe5697add4e9) clause.
205+
The [!INCLUDE[ssde_md](../../includes/ssde_md.md)] supports character and Unicode string constants that support enhanced collations. For more information, see the [COLLATE (Transact-SQL)](../../t-sql/statements/collations.md) clause.
198206

199207
## See also
200208
[Data Types (Transact-SQL)](../../t-sql/data-types/data-types-transact-sql.md)
201209
[Expressions (Transact-SQL)](../../t-sql/language-elements/expressions-transact-sql.md)
202210
[Operators (Transact-SQL)](../../t-sql/language-elements/operators-transact-sql.md)
203-
211+
[Collation and Unicode Support](../../relational-databases/collations/collation-and-unicode-support.md)
212+
[Collation Precedence](../../t-sql/statements/collation-precedence-transact-sql.md)
204213

0 commit comments

Comments
 (0)