varchar save English Chinese difference

Today, colleagues need to save the Chinese do not use the database type varchar nvarchar type should be used, and attach a blog to explain, usually work do not pay attention to this problem, thanks to my colleagues pointed out specially recorded at the following is the text ....

varchar in SQL Server is a single byte to store data, Chinese characters stored in the SQL Server will be saved as a two-byte, English characters to save the database, if the type field is varchar, it will only take a word section, and if the type field is nvarchar, it would occupy two bytes. varchar (40), can store the byte length of 40 characters, Chinese characters, when stored, because Chinese characters a character is equal to 2 bytes, so varchar (40) can store 20 Chinese characters. nvarchar (40), can store 40 Chinese characters, that can store up to 80 bytes in length characters. nvarchar with respect to the type of characters stored.
Under normal circumstances, we use varchar can store Chinese characters, but if you encounter operating system is English operating system and support for the Chinese font is not comprehensive, in SQL Server stored Chinese character varchar garbled (shown as ??) will appear. And under normal circumstances, the host will support Chinese environment, so if you use varchar to store data in the development stage can not be found. In most cases, when deployed there will not be a problem. but! If the deployment of the host operating system is in English, and does not support Chinese environment, the problem came out. All varchar fields to store Chinese is going to be garbled (shown as ??). But under normal circumstances you would not know this because you are using the wrong type of data to store the result, you will try to install Chinese fonts, try to set the operating system locale. . . These can not solve the problem, the only solution to the problem is the database field type personality is nvarchar (or nchar). Project management more familiar friends should all know, the deployment stage again to modify the database is a terrible thing.

(Turn: https://www.cnblogs.com/suncan0/p/4738255.html )

Guess you like

Origin www.cnblogs.com/hujinlong/p/11284211.html