简体   繁体   English

MySQL-基于另一个列值的单个列中有多个唯一集

[英]Mysql - Multiple unique sets in a single Column based on another column value

I must create a table for handling student data which has two columns department code and register number ,. 我必须创建一个用于处理学生数据的表,该表具有两列department coderegister number For Eg. 例如 dept 101 has 30 students with register numbers (1-30) And dept 102 has 30 different students with same register numbers (1-30) . 部门101有30名学生的注册号(1-30),部门102有30名不同学生的注册号相同(1-30) for instance.,The student with regno:3 who belongs to dept:101 and another student with regno:3 but in the dept:102 are in same table.,There can be same regno's but different dept code is there a way to relate my two columns.. I have added another image for more clarifications Table Structure with data My problem is how can i have unique set register numbers for each deparment in the same column to avoid duplication . 例如,具有regno:3的学生属于dept:101,而另一个具有regno:3的学生却在dept:102中位于同一表中。可以有相同的regno,但是有不同的dept代码可以关联我的两列..我添加了另一个图像以进一步阐明带有数据的表结构 我的问题是我如何才能在同一列中为每个部门有唯一的设置寄存器号以避免重复 The Values of reg_no with same Department Code must have a unique set,.. and another set of regno with a different dept_code must have another or individual set of unique set of numbers Can i Have Multiple unique sets in a single Column..?? 具有相同部门代码的reg_no值必须具有唯一的集合,..而具有不同的dept_code的另一组regno必须具有另一组或单独的唯一数字集。我可以在单个列中具有多个唯一集合。 The Table sample image 表格样本图片

Is there any solution or should i use another table for each dept_code 有什么解决方法还是我应该为每个dept_code使用另一个表

Tried on Googling didn't Get a result yet . 在Googling上尝试过尚未得到结果。 Thanks in Advance 提前致谢

try this 尝试这个

UNIQUE KEY 'thekey' ('dept','regno');

more about the background is found at this StackOverflow post 有关此背景的更多信息, 请参见此StackOverflow帖子

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

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