2

如何在 ms SQL server 中搜索用户名和密码等区分大小写的数据。在 MySQl 中是由BINARY()函数完成的。

4

2 回答 2

1

使用区分大小写的排序规则创建列,然后试试这个:

询问:

DECLARE @temp TABLE
(
      Name VARCHAR(50) COLLATE Latin1_General_CS_AS
)

INSERT INTO @temp (Name)
VALUES 
    ('Ankit Kumar'),
    ('DevArt'),
    ('Devart')

SELECT * 
FROM @temp
WHERE Name LIKE '%Art'

输出:

DevArt

或者试试这个类似的代码 -

DECLARE @temp TABLE (Name NVARCHAR(50))

INSERT INTO @temp (Name)
VALUES 
    ('Ankit Kumar'),
    ('DevArt'),
    ('Devart')

SELECT * 
FROM @temp
WHERE Name LIKE '%Art' COLLATE Latin1_General_CS_AS
于 2013-05-27T05:24:53.147 回答
1

可以使用 Casting to Binary 来做到这一点

SELECT * FROM UsersTable
WHERE   
    CAST(Username as varbinary(50)) = CAST(@Username as varbinary(50))
    AND CAST(Password as varbinary(50)) = CAST(@Password as varbinary(50))
    AND Username = @Username 
    AND Password = @Password
于 2013-05-27T05:29:33.527 回答