All the answers so far indicate that varchar
is single byte, nvarchar
is double byte. The first part of this actually depends on collation as illustrated below.
DECLARE @T TABLE
(
C1 VARCHAR(20) COLLATE Chinese_Traditional_Stroke_Order_100_CS_AS_KS_WS,
C2 NVARCHAR(20)COLLATE Chinese_Traditional_Stroke_Order_100_CS_AS_KS_WS
)
INSERT INTO @T
VALUES (N'???????',N'???????'),
(N'abc',N'abc');
SELECT C1,
C2,
LEN(C1) AS [LEN(C1)],
DATALENGTH(C1) AS [DATALENGTH(C1)],
LEN(C2) AS [LEN(C2)],
DATALENGTH(C2) AS [DATALENGTH(C2)]
FROM @T
Returns
Note that the ?
and ?
characters were still not represented in the VARCHAR
version and were silently replaced with ?
.
There are actually still no Chinese characters that can be reprsented by a single byte in that collation. The only single byte characters are the typical western ASCII set.
Because of this it is possible for an insert from a nvarchar(X)
column to a varchar(X)
column to fail with a truncation error (where X denotes a number that is the same in both instances).
SQL Server 2012 adds SC (Supplementary Character) collations that support UTF-16
. In these collations a single nvarchar
character may take 2 or 4 bytes.