What does the N in varchar(N) refer to when describing a field in a database. Is it the number of characters or bytes. Also, one is using UTF-8, a character may use more than one byte.
+3
A:
It's the maximum number of characters.
nvarchar(1000)
= max 1000 unicode chars.
Mehrdad Afshari
2009-04-16 10:54:11
+2
A:
varchar
cannot hold Unicode characters, so n
in varchar(n)
means both number of characters and number of bytes. In case of nvarchar(n)
the n
means the number of Unicode characters, with storage size of two times n
bytes.
If you query information_schema.columns
, there will be, among others, two columns of particular interest: CHARACTER_MAXIMUM_LENGTH
and CHARACTER_OCTET_LENGTH
. The former holds the number of characters, and the latter contains the number of bytes.
Anton Gogolev
2009-04-16 10:57:29