简体   繁体   English

普通条目的唯一条目?

[英]Unique entries for normal entries?

I am new to MySQL, and I have two columns. 我是MySQL的新手,我有两栏。 My desired table is the following: 我想要的表如下:

Column 1   Column 2
--------   --------
A          1
A          2
A          3
A          4
B          1
B          2
B          3
B          4

The problem I face, is for every row which has a value of A in column 1, column 2 must be unique, as seen above. 我面对的问题是,对于第1列中具有A值的每一行,第2列必须是唯一的,如上所述。 However duplicates in Column 2 are allowed aslong as the corresponding Column 1 value is different from that of other entries? 但是,只要对应的第1列的值与其他条目的值不同,是否允许在第2列重复?

I'm really sorry for the bad, wording, I'm just not sure how to ask the darn question. 我真的很抱歉,措辞不好,我只是不确定如何问这个问题。

The DDL command to add a unique constraint on multiple columns: DDL命令在多个列上添加唯一约束:

ALTER TABLE      `table_name` 
ADD UNIQUE INDEX (`column1`, `column2`);

您必须定义Column1Column2都是唯一的:

alter table YOUR_TABLE add unique index(Column1, Column2);

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

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