Several methods of case sensitive in SQL Server

xiaoxiao2021-03-06  63

Today, I met this question, asked my friends, gave the following solutions, I posted everyone to see: The first: (蟀) Alter Table TBALTER Column Colname NVARCHAR (100) Collate Chinese_PRC_CI_AS - Do not distinguish case ALTER TABLE tb ALTER COLUMN colname nvarchar (100) COLLATE Chinese_PRC_CS_AS - case-sensitive database alter database COLLATE Chinese_PRC_CS_AS second: (tree) - create the following user-defined function (UDF) cREATE fUNCTION StrComp (@ Str1 VARCHAR ( 50), @ str2 varchar (50)) - ALTER FUNCTION STRComp (@ str1 varchar (50), @ str2 varchar (50)) Returns IntegerasBegin Declare @i integer --Declare @ str1 varchar (50) - Declare @ str2 VARCHAR (50) DECLARE @Y INT --SET @ str1 = 'a' --set @ Str2 = 'a' set @ i = 0 --Select ASCII (Substring (@ STR1, @ i 1, 1)) SET @ y = 1 declare @ilen int set @ilen = LEN (Ltrim (r s (@ str1))))

Whether the database is case sensitive depends on the installation of SQL Server. If the database area is case sensitive, the search criteria must be constructed with the correct case in the correct case. For example, if you search for the name "Smith", you cannot use the search criteria "= SMITH" or "= SMITH".

Alternatively, if the server is installed into case sensitive, the name of the database, owner, table, and column must be provided with the correct case. If the name of the name is not matched, SQL Server returns an error and reports "invalid object name".

When you create a query using the relationship chart and the grid pane, the query designer always reflects whether the server is case sensitive. However, if you enter a query in the SQL pane, you must pay attention to match the name of the name with the server. If the server is installed with uncarded options, prompt to determine if the server is case sensitive, perform the stored procedure sp_server_info, then check the contents of the 18th line. If the server is installed with uncarded settings, the sort_order option will be set to "Not Case Size". You can run the stored procedure from the query analyzer. The fourth type: (non-cloud) Select * from Servers WHERE Convert (varbinary, name) = Convert (varbinary, n'rockey ') fifth: ()

ASCII ('a') is used with Substring ()

转载请注明原文地址:https://www.9cbs.com/read-88462.html

New Post(0)