Friday, April 29, 2011

What does the N in varchar(N) refer to

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.

From stackoverflow
  • It's the maximum number of characters.

    nvarchar(1000) = max 1000 unicode chars.

    1. nr of characters
  • 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.

0 comments:

Post a Comment