views:

98

answers:

3

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
+1  A: 
  1. nr of characters
Zaagmans
+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