Hello I wonder if there is way to disable repeating value in SQL Server 2012. I don't want several people to have the same login. As a primary key I am using ID. Should I change primary key from ID to Login ?
Asked
Active
Viewed 36 times
2 Answers
4
Declare the login to be unique.
Or, equivalently, create a unique index on login:
create unique index table_login on table(login);
Gordon Linoff
- 1,198,228
- 53
- 572
- 709
3
First off, you should never store a password as plain text in the database. Store an encrypted string if the password must be recoverable, but better yet store a salted hash of the password.
You could enforce your rule by creating a unique constraint on the Login column.
Eric J.
- 143,945
- 62
- 324
- 540
-
I did make some research, maybe you know some good tutorial with example ? – user2121038 Dec 18 '13 at 03:33
-
1For a reference on hash/salting a password, see http://stackoverflow.com/questions/876342/storing-passwords-in-sql-server – Eric J. Dec 18 '13 at 03:39