Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The condition field in Microsoft SQL Server is of Nvarchar type, and the reason why the condition cannot be queried in Chinese and how to deal with it

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

What is included in the condition cannot be queried in Chinese, because the field sender_su_name is of type nvarchar and needs to be preceded by N

SELECT * FROM [test] .[ dbo] .[ ship _ User_Email] WHERE [sender_su_name] = N' reward'

Why do you take N to explain as follows:

Working with Unicode data

The Unicode standard defines a single encoding scheme for most characters that are widely used in the global business world. All computers are consistently translated into characters using bit patterns in a single Unicode standard Unicode data. This ensures that the same bit pattern is always converted to the same character on all computers. Data can be freely transferred from one database or computer to another without worrying about whether the receiving system will mistakenly translate the bit pattern.

One of the problems with data types that encode each character with one byte is that this data type can only represent 256 different characters. This forces multiple coding specifications (or code pages) for different alphabets (such as the relatively small European alphabet). It is also impossible to deal with an alphabet with thousands of characters, such as Japanese or Korean characters.

Every Microsoft? SQL Server? The collation has a code page that defines the bit pattern for each character that represents the char, varchar, and text values. Individual columns and character constants can be assigned different code pages. The client computer interprets the character bit pattern using the code page associated with the operating system locale. There are many different code pages. Some characters appear on some code pages, but not on others. Some characters are defined with one bit pattern on some code pages and another bit pattern on other code pages. When you design international systems that must deal with different languages, it becomes difficult to select code pages for all computers in order to meet the language needs of different countries. It is also difficult to ensure that each computer has a correct translation when interacting with a system that uses different code pages.

The Unicode specification solves this problem by using two bytes to encode each character. The single specification for converting the most common business language has enough 2-byte patterns (65536). Because all Unicode systems consistently use the same bit pattern to represent all characters, there will be no problem of incorrect character conversion when moving from one system to another. Character conversion problems can be minimized by using the Unicode data type throughout the system.

In Microsoft SQL Server, the following data types support Unicode data:

Nchar

Nvarchar

Ntext

The prefix n that indicates these data types comes from the National (Unicode) data type in the SQL-92 standard.

The use of nchar, nvarchar, and ntext is the same as that of char, varchar, and text, respectively, but differs in the following ways:

Unicode supports a wider range of characters.

More space is required to store Unicode characters.

Nchar and nvarchar columns can have up to 4000 characters instead of 8000 characters like char and varchar characters.

The Unicode constant is specified with the beginning of N: Numba Unicode string'.

All Unicode data uses the same Unicode code page. Collations do not control the code page used for Unicode columns, only characteristics such as comparison rules and case sensitivity.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report