0

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 ?

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user2121038
  • 153
  • 1
  • 3
  • 14

2 Answers2

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,242,037
  • 58
  • 646
  • 786
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.
  • 147,927
  • 63
  • 340
  • 553