Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我们可以在连接表中使一对值唯一吗?两张桌子(学生和教室)有多对多的关系。我创建了一个仅包含 Studentid 和 Classroom id 的联结表。但我不希望同一对被 enetered 两次。例如(学生编号:33 教室编号:5)。请帮忙!!!
在两列上添加唯一索引:
ALTER TABLE `junction` ADD UNIQUE ( `student_id` , `classroom_id` )
如果您尝试两次输入相同的组合,则 mysql 端将出现错误。