根据另一个字段使一个字段唯一

Aha*_*adh 5 php mysql sql

我有以下MySQL表..

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
Run Code Online (Sandbox Code Playgroud)

所有的插槽都在同一天,因此用户可以输入他空闲的一天中的不同时间.

现在我做了这个并且它有效,现在我偶然发现了一个问题.我为一个用户输入了一些数据,现在当我尝试为同一日期输入另一个用户的数据时,我不能说它已经存在了.

我如何制作它以便我可以让同一个用户输入多个日期而另一个用户输入相同的日期?...但是同一个用户不能两次输入相同的日期...如何做到这一点?

Dan*_*llo 4

您可能想在和PRIMARY KEY上使用复合。user_iddate

您也可以按照Quassnoi 的建议使用唯一键,但看起来您的字段本身并不是主键的有效候选者date