Answers:
可以通过更改Collation来完成。默认情况下,它不区分大小写。
链接摘录:
SELECT 1
FROM dbo.Customers
WHERE CustID = @CustID COLLATE SQL_Latin1_General_CP1_CS_AS
AND CustPassword = @CustPassword COLLATE SQL_Latin1_General_CP1_CS_AS
或者,将列更改为区分大小写。
/schwarz-weiß
与:/schwarz-weiss
通过使用归类或强制转换为二进制,如下所示:
SELECT *
FROM Users
WHERE
Username = @Username COLLATE SQL_Latin1_General_CP1_CS_AS
AND Password = @Password COLLATE SQL_Latin1_General_CP1_CS_AS
AND Username = @Username
AND Password = @Password
用户名/密码的重复存在使引擎可以使用索引。上面的排序规则是区分大小写的排序规则,如有必要,请更改为所需的排序规则。
第二个,转换为二进制,可以这样完成:
SELECT *
FROM Users
WHERE
CAST(Username as varbinary(100)) = CAST(@Username as varbinary))
AND CAST(Password as varbinary(100)) = CAST(@Password as varbinary(100))
AND Username = @Username
AND Password = @Password
like "*word or phrase*"
SQL搜索的词组将插入何处,则该答案将是完美的。
您可以使用convert to varbinary进行查询-非常简单。例:
Select * from your_table where convert(varbinary, your_column) = convert(varbinary, 'aBcD')
使用BINARY_CHECKSUM
SELECT
FROM Users
WHERE
BINARY_CHECKSUM(Username) = BINARY_CHECKSUM(@Username)
AND BINARY_CHECKSUM(Password) = BINARY_CHECKSUM(@Password)
使用HASHBYTES
declare @first_value nvarchar(1) = 'a'
declare @second_value navarchar(1) = 'A'
if HASHBYTES('SHA1',@first_value) = HASHBYTES('SHA1',@second_value) begin
print 'equal'
end else begin
print 'not equal'
end
-- output:
-- not equal
...在where子句中
declare @example table (ValueA nvarchar(1), ValueB nvarchar(1))
insert into @example (ValueA, ValueB)
values ('a', 'A'),
('a', 'a'),
('a', 'b')
select ValueA + ' = ' + ValueB
from @example
where hashbytes('SHA1', ValueA) = hashbytes('SHA1', ValueB)
-- output:
-- a = a
select ValueA + ' <> ' + ValueB
from @example
where hashbytes('SHA1', ValueA) <> hashbytes('SHA1', ValueB)
-- output:
-- a <> A
-- a <> b
或寻找价值
declare @value_b nvarchar(1) = 'A'
select ValueB + ' = ' + @value_b
from @example
where hashbytes('SHA1', ValueB) = hasbytes('SHA1', @value_b)
-- output:
-- A = A
在MySQL中,如果您不想更改排序规则并希望执行区分大小写的搜索,则只需使用如下所示的二进制关键字:
SELECT * FROM table_name WHERE binary username=@search_parameter and binary password=@search_parameter