我有这种情况:
MySQL - Newbie question: Which are the PK and the FK for these tables? (看看表格薪水)
如何创建具有多个主键的表?
create table salaries
(
dep_id smallint auto_increment primary key,
emp_id smallint auto_increment primary key,
bla varchar(20)
);
如果我尝试上面的代码,我会收到一个错误。有什么想法吗?
最佳答案
一张表只能有一个主键。但是,主键可以包含多个列,例如
CREATE TABLE salaries (
dep_id SMALLINT UNSIGNED NOT NULL,
an_id SMALLINT UNSIGNED NOT NULL,
bla VARCHAR(20),
PRIMARY KEY (dep_id, an_id)
);
关于sql - Mysql:如何创建具有多个主键的表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1590597/