MySql表,错误#1064&错误#1068定义了多个主键

时间:2013-05-22 16:22:41

标签: mysql sql create-table

我尝试安装MySql表时遇到错误,错误:

  

“#1064 - 您的SQL语法出错”

和错误:

  

“#1068 - 定义了多个主键”

这是数据库:

CREATE TABLE messages (
msg_id INT PRIMARY KEY AUTO_INCREMENT,
message VARCHAR(200),
uid_fk INT(10),
ip VARCHAR(45),
created INT(10),
uploads VARCHAR(50),
profile_uid INT(10)

PRIMARY KEY (`msg_id`),
KEY `uid_fk` (`uid_fk`)

);


CREATE TABLE comments (
com_id INT PRIMARY KEY AUTO_INCREMENT,
comment VARCHAR(200),
msg_id_fk INT(10),
uid_fk INT(10),
ip VARCHAR(45),
created INT(10),

PRIMARY KEY (`com_id`),
KEY `msg_id_fk` (`msg_id_fk`),
KEY `uid_fk` (`uid_fk`)

);


CREATE TABLE likes (
like_id INT PRIMARY KEY AUTO_INCREMENT,
msg_id_fk INT(10),
uid_fk INT(10),

PRIMARY KEY (`like_id`),
KEY `msg_id_fk` (`msg_id_fk`),
KEY `uid_fk` (`uid_fk`)

);


CREATE TABLE user_uploads (
id INT PRIMARY KEY AUTO_INCREMENT,
image_path VARCHAR(500),
uid_fk INT(10),

PRIMARY KEY (`id`),
KEY `uid_fk` (`uid_fk`)

);


CREATE TABLE follow_user (
fid INT PRIMARY KEY AUTO_INCREMENT,
uid_fk INT(10),
following_uid INT(10),

PRIMARY KEY (`fid`),
KEY `uid_fk` (`uid_fk`)

);

这些是错误图片:

如何解决?

2 个答案:

答案 0 :(得分:7)

使用内联语法(msg_id INT PRIMARY KEY AUTO_INCREMENT)或之后声明(PRIMARY KEY ( com_id )),而不是两者:它们发生冲突。

答案 1 :(得分:0)

消息表中的语法错误只是profile_uid INT(10)行末尾缺少逗号。