我希望SQL服务器中的两个select语句在一列中使用或 [英] I want two select statements in SQL server in one column using or

查看:56
本文介绍了我希望SQL服务器中的两个select语句在一列中使用或的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表,即学生和用户。在学生表中,我有字段ID,名称,密码。在用户表中,我有id,名称,密码等。



现在我的问题是只在存储过程中选择两个带密码列的表。在这一行中,我想使用OR来选择两个表。我要求的是,如果用户更改密码,则必须检查用户是否在学生表或用户表中。为此,我将一个值设置为局部变量,该变量访问表并更新密码。



此密码字段varchar(max)数据类型



我尝试过:



i have two tables namely student and users. In student table i am having fields Id, Name, Password. In users table i am having id, name, password etc.

Now my question is select two tables with password column only in stored procedure. In this line i want to use OR for selecting two tables. Why i require is if the user changes the password then it has to check whether the user is in the student table or user table. For this i am setting a value to local variable with that variable accessing the tables and updating the password.

This password fields varchar(max) datatype

What I have tried:

SET @@CurrentPassword4db = ((SELECT [Password] FROM Users WHERE UserId = @guidUserId) OR (SELECT [Password] FROM Student WHERE StudentId = @guidStudentId))





任何人都可以告诉我实现这一目标的正确方法。在此先感谢

这里



Can anyone tell me the correct way to achieve this goal. Thanks in advance
Here

@@CurrentPassword4db is varchar(max)

datatype

推荐答案

这里有几个问题:

1)永远不要以明文形式存储密码 - 这是一个巨大的安全问题。应对密码进行哈希处理,并将哈希值存储在DB中。这需要更改您的演示文稿软件,这里有一个C#示例:密码存储:怎么做。 [ ^ ]



2)为什么有两个表存储相同的东西?这只会带来潜在的重复和问题。相反,让一个表格显示一列,表明该行是针对用户还是学生。这样,所有登录,注册,更改密码等代码都变成了整个负载清理器,因为它们都存储在同一个地方。使用您的方案,很有可能在两个不同的表中获得相同的用户ID,然后您永远不知道发生了什么!
Several things wrong here:
1) Never store passwords in clear text - it is a massive security problem. Passwords should be hashed, and the hash value stored in the DB. This requires changes to your presentation software, and there is an example here for C#: Password Storage: How to do it.[^]

2) Why have two tables storing the same thing? That just risks potential duplication and problems. Instead, have one table with a column that says if the row is for a User or a Student. That way all your login, registration, change password, etc. code becomes a whole load cleaner as it is all stored in the same place. With your scheme, it's quite possible to get the same userID in two different tables and then you never know what is going on!


这篇关于我希望SQL服务器中的两个select语句在一列中使用或的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆