更新时间:2022-12-03 15:00:37
Primary Key 旨在唯一
Primary Key is intended to be unique
http://dev.mysql.com/doc/refman/5.5/en/optimizing-primary-keys.html
你可以有一个复合主键:
CREATE TABLE track(
album CHAR(10) NOT NULL,
dsk INTEGER NOT NULL,
posn INTEGER NOT NULL,
song VARCHAR(255),
PRIMARY KEY (album, dsk, posn)
)
复合唯一键在您想要防止表中多个数据库字段中出现重复数据时非常有用.
Composite unique keys are very useful for when you want to prevent duplicate data across a number of database fields in a table.
http://www.alphadevx.com/a/382-Adding-a-composite-unique-key-to-an-existing-MySQL-table