簡體   English   中英

MySQl錯誤#1064 42000

[英]MySQl Error #1064 42000

創建“訂單”表時,我總是收到錯誤消息。 有任何想法嗎? “客戶”表已經存在, cust#列也已存在。 提前致謝。

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; 

編輯:只是一個錯字。 感謝您的回復。

在創建表orders之前,表customer必須存在。

觀看演示

雖然允許使用諸如#類的字符,但在命名對象時應避免使用它們。

嘗試為外鍵添加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