Differences between varchar and nvarchar field types in SQL

Source: Internet
Author: User
Tags character set numeric numeric value
sql| Difference |varchar| field type

What is the difference between nvarchar and varchar in SQL Server 2000?

SQL Server provides two types of data to store character information. The two data types are roughly the same in how they are used in SQL Server or applications. The difference is that nvarchar is used to store Unicode data that handles multilingual data in a database diagram. Other languages have an extended set of character codes that need to be saved, and this type of data supports such extensions. Because of the need to store extended character codes for other languages, nvarchar occupies twice times more space than varchar.

Character, English characters only need one byte of storage is sufficient, but the number of Chinese characters, the need for two bytes of storage, English and Chinese characters at the same time can cause confusion, the Unicode character set is to solve the character set this incompatibility problem, all of its characters are expressed in two bytes, The English character is also expressed in two bytes.

For example, two fields have field values: me and coffee. The varchar field occupies a 2x2+6=10 byte of storage space, while the nvarchar field occupies 8x2=16 bytes of storage space. If the field value is only English can choose varchar, while the field value exists more double-byte (Chinese, Korean, etc.) characters with nvarchar

varchar[(N)]

A variable length of n bytes and non-Unicode character data. n must be a numeric value between 1 and 8,000. The actual length of the byte that the storage size is the input data, not the N bytes. The length of the data character entered can be zero. The synonyms for varchar in SQL-92 are char varying or character varying.

nvarchar (n)

Variable-length Unicode character data containing n characters. The value of n must be between 1 and 4,000. The storage size of bytes is twice times the number of characters entered. The length of the data character entered can be zero. The synonyms for nvarchar in SQL-92 are national char varying and national character varying.
varchar[(N)]

A variable length of n bytes and non-Unicode character data. n must be a numeric value between 1 and 8,000. The actual length of the byte that the storage size is the input data, not the N bytes. The length of the data character entered can be zero. The synonyms for varchar in SQL-92 are char varying or character varying.

nvarchar (n)

Variable-length Unicode character data containing n characters. The value of n must be between 1 and 4,000. The storage size of bytes is twice times the number of characters entered. The length of the data character entered can be zero. The synonyms for nvarchar in SQL-92 are national char varying and national character varying.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.