Click here to Skip to main content
15,937,779 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
@@CurrentPassword4db is varchar(max)
Updated 29-Sep-18 21:41pm

1 solution

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!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900