Make one field unique depending on another field

I have the following MySQL table.

userid - foreign key
date   - primary key
slot1  - 1st free slot
slot2  - 2nd free slot
slot3  - 3rd free slot
slot4  - 4th free slot
slot5  - 5th free slot
slot6  - 6th free slot
slot7  - 7th free slot
slot8  - 8th free slot

All slots are for one day, so the user can enter different times of the day when he is free.

Now I did it, and it worked, and now I came across a problem. I entered some data for one user, and now when I try to enter data for another user for the same date, I can not, because he says that he already exists.

How can I make it possible for the same user to enter several dates and the other user to enter the same date? ... But the same user cannot enter the same date twice ... How can this to be done?

+5
source share
2

PRIMARY KEY user_id date.

Quassnoi, , , date .

+4
ALTER TABLE mytable ADD CONSTRAINT ux_mytable_user_date UNIQUE KEY (user, date)

PRIMARY KEY date.

user_id, date ( ), , , PRIMARY KEY (, AUTO_INCREMENT).

+3

All Articles