简体   繁体   English

MySQL设计表

[英]MySQL design tables

We have 3 tables. 我们有3张桌子。

Instructor
ID (PK, AI)
Name
Surname


Activity
ID (PK, AI)
Name

given_activity
A_ID (FK to Activity ID)
I_ID (FK to Instructor ID)
Slot (PK)

we have designed our tables like this, but we could not satisfy this condition; 我们已经像这样设计了表格,但是我们不能满足这个条件;

"a instructor should not give an activity at the same time" “教员不应同时进行活动”

how could we change our tables? 我们如何改变桌子?

您的主键可以帮助您在给定的表上创建主键

PRIMARY KEY(a_id,i_id)

The condition: 条件:

an instructor should not give an activity at the same time 讲师不应同时进行一项活动

Is saying that there are no duplicates for instructor/slot in given_activity . 是说给定的活动中教员/槽位没有重复given_activity You can accomplish this with a unique index/constraint: 您可以使用唯一的索引/约束来完成此操作:

create unique index unq_givenactivity_instructor_slot on given_activity(I_ID, slot);

@davejal @davejal

making a_id and i_id PK will cause that 进行a_id和i_id PK将导致

"an instructor can not give an activity in different times" “讲师不能在不同时间进行活动”

a_id (PK)     i_id (PK)      slot
1             2              10-12
1             2              12-14

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM