Reputation: 1068
I have one table with following columns
Id fksur_id name email
I want to do like this..and it is fine.
fksur_id email
2 [email protected]
2 [email protected]
this is not ok
fksur_id email
2 [email protected]
2 [email protected]
I would like to know how shall i have to restrict if same email address is being inserted along with same fksur_id. here i want to have duplicate fksur_id with different email or duplicate email with different fksur_id. any help would be appreciated.
Upvotes: 2
Views: 152
Reputation: 7668
here is SQLFiddle
ALTER TABLE table_name ADD PRIMARY KEY(FKSUR_ID, EMAIL);
If a primary key already exists then you want to do this
ALTER TABLE table_Name ADD CONSTRAINT CONSTRAINTNAME UNIQUE (FKSUR_ID, EMAIL);
Upvotes: 2
Reputation: 423
Use Unique Index with 2 columns in. http://dev.mysql.com/doc/refman/5.7/en/create-index.html
Upvotes: 1
Reputation: 4799
Why not just do a SELECT, see if it returns any results and if not, then perform the INSERT?
Upvotes: 0