Unicode character strings

Unicode character strings#

Unicode character data using the UCS-2 character set, independent of collation. Fixed-length (nchar) or variable-length (nvarchar); ntext is the legacy large-object variant.

  • nchar

  • nvarchar

  • ntext

nchar and nvarchar#

Character data types that are either fixed-length (nchar) or variable-length (nvarchar) Unicode data, using the UCS-2 character set.

nchar [ ( n ) ] Fixed-length Unicode string data. n defines the string length and must be a value from 1 through 4,000. The storage size is two times n bytes.

nvarchar [ ( n | max ) ] Variable-length Unicode string data. n defines the string length and can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size, in bytes, is two times the actual length of data entered + 2 bytes.

Example:

CREATE TABLE dbo.MyTable
(
    MyNCharColumn nchar(15)
, MyNVarCharColumn nvarchar(20)
);

INSERT INTO dbo.MyTable VALUES (N'Test data', N'More test data');

SELECT MyNCharColumn, MyNVarCharColumn
FROM dbo.MyTable;

ntext#

Variable-length Unicode data with a maximum string length of 2^30-1 (1,073,741,823) characters, using the UCS-2 character set. Storage size, in bytes, is two times the string length entered.

See also#