简体   繁体   English

MySQl错误#1064 42000

[英]MySQl Error #1064 42000

I keep getting an error when creating the "orders" table. 创建“订单”表时,我总是收到错误消息。 Any ideas? 有任何想法吗? "customer" table already exists, as does the cust# column. “客户”表已经存在, cust#列也已存在。 Thanks in advance. 提前致谢。

create table orders(
`order#` char(4) not null,
orderdate date not null,
`cust#` char(4) not null,
amount decimal(10,2) not null,
primary key (`order#`),
foreign key (`cust#`) references customer (`cust#`)
on delete cascade on update cascade
) engine=InnoDB; 

EDIT: simply a typo. 编辑:只是一个错字。 thanks for your responses. 感谢您的回复。

Table customer must exist before trying to create table orders . 在创建表orders之前,表customer必须存在。

See a demo . 观看演示

While characters such as # are permitted, they should be avoided in naming objects. 虽然允许使用诸如#类的字符,但在命名对象时应避免使用它们。

Try adding CONSTRAINT for the foreign key. 尝试为外键添加CONSTRAINT

create table orders(
`order#` char(4) not null,
orderdate date not null,
`cust#` char(4) not null,
ord_amt decimal(10,2) not null,
primary key (`order#`),
CONSTRAINT `fk_cust` foreign key (`cust#`) references customer (`cust#`)
on delete cascade on update cascade
) engine=InnoDB; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM