需要有关SQL查询的帮助 [英] Need help for SQL query
问题描述
如何编写sql查询以检索给定用户的user_id,user_name和密码?
我已编写查询
选择 USER_ID,USER_NAME,PASSWORD FROM NC_USER @ USERNAME ;
USERNAME将由最终用户提供.
在我的mysql数据库中,用户表以小写形式保存.
示例:
user_id用户名密码
1 chinmoyp m
2处mi
3 radhamadhaba分钟
4 bhagirathip心灵
5 rashmis mindf
当我输入"CHinmOYp"时,它显示结果.
user_id用户名密码
1 chinmoyp m
但实际上它应该说出无效的用户名(错误).
如何编写查询,以便如果我们输入"ChinmOYp",则会显示一条错误消息,提示用户名不存在.
请提出建议
谢谢
您可以尝试一下..
SELECT USER_ID,USER_NAME,PASSWORD FROM NC_USER 喜欢 @USERNAME ;
此二进制关键字比较二进制值,以便您可以解决问题
您可以通过将COLLATION强制设置为区分大小写来做到这一点:
选择 USER_ID,USER_NAME,PASSWORD FROM NC_USER @ USERNAME SELECT USER_ID,USER_NAME,PASSWORD FROM NC_USER WHERE USER_NAME = @USERNAME;
here USERNAME will be give by the end user.
In my mysql database the user table is saved in lower case.
Example:
user_id user_name password
1 chinmoyp m
2 sumitd mi
3 radhamadhaba min
4 bhagirathip mind
5 rashmis mindf
when i enter ''CHinmOYp'' it is showing result.
user_id user_name password
1 chinmoyp m
But actually it should say invalid user name(error).
How to write a query so that the if we enter ''ChinmOYp'' it will show an error message that the user name is not present.
Please Suggest
Thanks解决方案You can try this..
SELECT USER_ID,USER_NAME,PASSWORD FROM NC_USER WHERE USER_NAME LIKE BINARY @USERNAME;
this binary keyword compares binary values so u can solve your problem
You can do it by forcing the COLLATION to case sensitive:
SELECT USER_ID,USER_NAME,PASSWORD FROM NC_USER WHERE USER_NAME = @USERNAME COLLATE SQL_Latin1_General_CP1_CS_AS
这篇关于需要有关SQL查询的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!