SQL Server String case sensitivity method

Source: Internet
Author: User
By default, SQLServer is case insensitive. For example, userNamejesse and userNameJESSE have the same results. When the password is verified, it may be case sensitive to the string and some processing is required. Two methods are introduced: method I: Convert to binary and then compare, because the case-sensitive ASC code is different. Example: select * fromT _

By default, SQL Server is case insensitive. For example, userName = 'jesse 'and userName = 'jesse' have the same results. When the password is verified, it may be case sensitive to the string and some processing is required. Two methods are introduced: method I: Convert to binary and then compare, because the case-sensitive ASC code is different. Example: select * from T _

By default, SQL Server is case insensitive. For example, userName = 'jesse 'and userName = 'jesse' have the same results. When verifying the password, you may need to be case sensitive to the string. You need to perform some processing to introduce two methods:

Method I: Convert to binary before comparison, because the case-sensitive ASC code is different. For example:

Select *

From T_User

Where cast (field as varbinary) = cast ('admin' as varbinary)

Method II: sorting rules are also based on binary. Add collate Chinese_PRC_CS_AS_WS to the field

For example:

Select *

From T_User

Where userName = 'admin' and password collate Chinese_PRC_CS_AS_WS = 'admin'

Case sensitivity is related to sorting rules. The meaning of each part of the sorting rules is as follows:

Example: Chinese_PRC_CS_AI_WS

First half: the UNICODE character set. The Chinese_PRC _ pointer sorts UNICODE in simplified Chinese characters.

The second half of the sorting rule is the suffix meaning:

_ BIN binary sorting

_ CI (CS) is case sensitive, CI is case insensitive, and CS is case sensitive

_ Whether AI (AS) distinguishes stress, AI does not distinguish,

Whether the _ KI (KS) class is Kana type. The KI class is not differentiated, and the KS class is differentiated.

_ Whether WI (WS) is differentiated by width WI and WS

Case Sensitive: select this option if you want to make the comparison between uppercase and lowercase letters different.

Accent differentiation: select this option if you want to treat the comparison as different from the accent and non-accent letters. If this option is selected, the comparison also treats the homophone with different accents as unequal.

Kana differentiation: select this option if you want to treat Katakana and katakana as different Japanese syllables.

Width differentiation: select this option if you want to make the comparison between halfwidth and fullwidth characters.

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.