Mysql SQL错误代码:无法打开引用的表";产品;?

Mysql SQL错误代码:无法打开引用的表";产品;?,mysql,Mysql,我是SQL的新手,在创建引用(products)表的外键(orderdetails)时出错 由于表在代码中的创建顺序,您指的是尚未创建的表产品 尝试以这种方式更改创建顺序 你指的是t create table products ( productCode varchar(15) primary key , productName varchar(70) not null , productLine Varchar(50) not null, productScale varchar(10) n

我是SQL的新手,在创建引用(products)表的外键(orderdetails)时出错


由于表在代码中的创建顺序,您指的是尚未创建的表产品

尝试以这种方式更改创建顺序 你指的是t

create table products ( 
productCode varchar(15) primary key ,
productName varchar(70) not null ,
productLine Varchar(50) not null,
productScale varchar(10) not null,
productVendor varchar(50) not null,
productDescription text not null , 
quantityInStock smallint not null , 
buyPrice double not null  ,
constraint fk_productLine foreign key (productLine) references 
productlines ( productLine) on delete restrict on update cascade 
 ) engine = InnoDB ; 


// creat tabale orderdetails
create table orderdetails (
orderNumber Int(11) not null   ,
productCode varchar(15) not null , 
quantityOrdered Int(11)  not null ,
priceEach Double not null , 
orderLineNumber smallint(6) not null  ,

constraint  fk_order_number foreign key (orderNumber) references
orders ( orderNumber) on delete restrict on update cascade ,

constraint fk_productCode foreign key  ( productCode) references
products (productCode) ,
constraint fk_key primary key( orderNumber, productCode )

一些意见:1。代理主键除了是一个自动递增的整数外,没有其他任何理由。2.钱很少是双倍的。这就是十进制被发明的原因。非常感谢
create table products ( 
productCode varchar(15) primary key ,
productName varchar(70) not null ,
productLine Varchar(50) not null,
productScale varchar(10) not null,
productVendor varchar(50) not null,
productDescription text not null , 
quantityInStock smallint not null , 
buyPrice double not null  ,
constraint fk_productLine foreign key (productLine) references 
productlines ( productLine) on delete restrict on update cascade 
 ) engine = InnoDB ; 


// creat tabale orderdetails
create table orderdetails (
orderNumber Int(11) not null   ,
productCode varchar(15) not null , 
quantityOrdered Int(11)  not null ,
priceEach Double not null , 
orderLineNumber smallint(6) not null  ,

constraint  fk_order_number foreign key (orderNumber) references
orders ( orderNumber) on delete restrict on update cascade ,

constraint fk_productCode foreign key  ( productCode) references
products (productCode) ,
constraint fk_key primary key( orderNumber, productCode )