windy401 Asked: 2017-10-31 19:26:18 +0800 CST2017-10-31 19:26:18 +0800 CST 2017-10-31 19:26:18 +0800 CST 添加 FOREIGN KEY REFERENCE 后出现语法错误 772 我在下面的代码中收到了显示的错误,从第二张图片中显示的教程中复制了外键行内容。即使整天看了这个教程和其他教程,我仍然没有看到问题出在哪里。有人可以指出什么问题吗? mysql database-design 1 个回答 Voted Best Answer stefan 2017-10-31T22:05:28+08:002017-10-31T22:05:28+08:00 尝试: ... poster int references user(userid) ... 例如 mysql> create table user ( uname varchar(15) primary key ) ; Query OK, 0 rows affected (0.01 sec) mysql> create table note ( -> title int primary key -> , poster int references user(userid) -> ); Query OK, 0 rows affected (0.00 sec) 或者 ... alter table note add constraint user_fk foreign key (poster) references user(uname); 例如 mysql> create table user ( uname varchar(15) primary key ) ; Query OK, 0 rows affected (0.00 sec) mysql> create table note ( -> title int primary key -> , poster varchar(15) -> ); Query OK, 0 rows affected (0.00 sec) mysql> alter table note -> add constraint user_fk -> foreign key (poster) references user(uname); Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0
尝试:
例如
或者 ...
例如