The number of database storage character type characters and Chinese characters

sqlServer2012 (936 Simplified Chinese GBK) as an example:

E.g:

  varchar (10), can store 10 English characters or numbers, only 5 characters stored;

  char (10), can store 10 English characters or numbers, only 5 characters stored;

  nvarchar (10), i.e., the storage 10 English characters or numbers, can store 10 characters;

  nchar (10), i.e., the storage 10 English characters or numbers, can store 10 characters;

  varchar (max), a large value data type may be stored up to 2 ^ 30-1 bytes of data (VARCHAR ( max ), nvarchar ( max ), a varbinary ( max ))

summary:

Unicode character set the character set is to solve this incompatibility problem arising, with all its characters are two bytes, ie the English characters is represented by two bytes.
The prefix n says Unicode characters, such as nchar, nvarchar, both types use the Unicode character set.

 

 Will exceed the size of an error.

Additional information:

Varchar difference in sql server and the Nvarchar:
1. Varchar byte length according to the actual storage, a 1-byte characters, an English one byte, a length of between 1 and 8000, the storage size of the input data word the actual length of the segments
2. Nvarchar by the number of characters stored, whether Chinese or English, is 2 bytes, a length between 1 and 4000, the memory size is twice the number of characters (n input prefix, n is expressed Unicode characters, i.e. all characters accounted for two bytes)
3. from the storage, nvarchar by character is stored, and the byte is stored varchar
4. from the storage considerations, varchar comparison save space, since the memory size is the actual length byte and double-byte storage nvarchar
5. If you do the project may involve conversion between different national languages, suggested nvarchar, nvarchar is because the use of Unicode encoding will reduce the odds of garbled
6 . Char / NChar fixed length data types, English supplement insufficient half-size space.

LEN () function: returns a character string expression is given (rather than byte) number, which does not include a trailing space. (Len only returns the number of characters, a character representing a character)
DATALENGTH () function: returns the number of bytes occupied by any expression. (DATALENGTH returns the number of bytes, a two-byte characters)
Len () not including spaces length, the DATALENGTH () spaces.

 

mysql:

In version 5.5.49, the character set is utf-8, the number of Chinese characters and English char (10) and varchar (10) are stored in 10

 

Guess you like

Origin www.cnblogs.com/lzghyh/p/11975144.html