Differences between CHAR, NCHAR, VARCHAR and NVARCHAR?

 Updated on October 28, 2014     VIKRAM     998

CHAR:

char [ ( n ) ]

  • The storage size is n bytes.
  • The ISO synonym for char is character.

Note:

  1. When n is not specified in a data definition or variable declaration statement, the default length is 1.
  2. Use char when the sizes of the column data entries are consistent.

VARCHAR:

varchar [ ( n | max ) ]

  • Variable-length, non-Unicode string data. 
  • n defines the string length and can be a value from 1 through 8,000. 
  • max indicates that the maximum storage size is 2^31-1 bytes (2 GB).
  • The storage size is the actual length of the data entered 2 bytes.
  • The ISO synonyms for varchar are char varying or character varying.

Note:

  1. When n is not specified in a data definition or variable declaration statement, the default length is 1
  2. When n is not specified when using the CAST and CONVERT functions, the default length is 30.
  3. Use varchar when the sizes of the column data entries vary considerably.
  4. Use varchar(max) when the sizes of the column data entries vary considerably, and the size might exceed 8,000 bytes.

NCHAR:

nchar [ ( n ) ]

  • Fixed-length Unicode string data. 
  • n defines the string length and must be a value from 1 through 4,000.
  • The ISO synonyms for nchar are national char and national character.

NVARCHAR:

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 ISO synonyms for nvarchar are national char varying and national character varying.

Note:

  1. When n is not specified in a data definition or variable declaration statement, the default length is 1
  2. When n is not specified with the CAST function, the default length is 30.

Read more detailed article with example here.

If you enjoyed this post, please like (or) share this article.


Comments