0

I have a question for basic sql setting For example

table

id lastname firstname
1  water    bob   
2  zet      ken
3  tem      nick
4  tem      ken
5  zet      nick

I dont need to set unique key on each columns though, I want to keep uniquenss on two columns combination

for example

6 water nick  // is OK

but

6 zet nick  // should be banned(it is identical to row5)

Is there any way to set this conditions on Mysql?

1

2 Answers 2

1

add unique index(lastname, firstname)

It's called a composite unique key.

1
  • THank you I undesrstood and made it to use this in dotorine.
    – whitebear
    Jun 15, 2013 at 5:50
0

create another key (Unique index or unique constraint) on combination of firstName, lastname. This is called a natural key, as opposed to the id column you have which is called a surrogate key.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.