[英]foreign key not creating in table
first table: 第一张桌子:
create table login(
id int auto_increment,
user varchar(20),
pass varchar(20),
primary key(id)
);
first table is created with primary key.. 第一个表是用主键创建的。
second table: 第二张表:
create table check(
cid int,
rid int,
usname varchar(20),
word varchar(20),
FOREIGN KEY(rid) REFERENCES login(id)
);
Error: 错误:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'check
(cid int, rid int, usname varchar(20), word varchar(20), FOREIGN KEY(rid) R' at
line 1
The problem isn't the foreign key. 问题不是外键。 check
is a reserved word in MySQL. 在MySQL中, check
是保留字。 So you need to choose another name or escape it: 因此,您需要选择另一个名称或对其进行转义:
create table `check`(
cid int,
rid int,
usname varchar(20),
word varchar(20),
FOREIGN KEY(rid) REFERENCES login(id)
);
Ironically, although it is a reserved word, it is not actually used. 具有讽刺意味的是,尽管它是保留字,但实际上并未使用。 Alas, I do wish that MySQL supported check
constraints. las,我确实希望MySQL支持check
约束。
check
is a key word in MySQL
; check
是MySQL
一个关键词; either surround it with backticks, `, or choose a different name. 或者用反引号将其包围,`,或选择其他名称。
Change the name of your table check
. 更改表check
的名称。 Check is a reserved word in MySQL Check是MySQL中的保留字
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.