使用ENGINE = INNODB

时间:2016-09-17 13:37:45

标签: mysql innodb

首先,首先,下面是我的代码。当我在学校的mysql服务器上运行时,我会收到ERROR 1005(HY000)。虽然此错误仅发生在客户,订单和odetails表中。我确实收到了一些警告。从我所做的研究来看,这是因为我错误地实施了innodb。我们非常感谢任何帮助,特别是因为这只是这项任务的开始步骤之一。

drop table IF EXISTS employees;
drop table IF EXISTS parts;
drop table IF EXISTS customers;
drop table IF EXISTS orders;
drop table IF EXISTS odetails;
drop table IF EXISTS zipcodes;

create table employees
    (eno        numeric(4,0),
     ename      varchar(15),
     zip        numeric(5,0),
     hdate      date default null,
     primary key (eno),
     foreign key (zip) references zipcodes (zip)
    )ENGINE=InooDB;

create table parts
    (pno        numeric(5,0),
     pname      varchar(30),
     qoh        numeric(3,0),
     price      numeric(10,2),
     level      numeric(2,0),
     primary key (pno)
    )ENGINE=InnoDB;

create table customers
    (cno        numeric(4,0),
     cname      varchar(15),
     street     varchar(30),
     zip        numeric(5,0),
     phone      varchar(12),
     primary key (cno),
     foreign key (zip) references zipcodes (zip))
     ENGINE=InnoDB;

create table orders
    (ono        numeric(4,0),
     cno        numeric(4,0),
     eno        numeric(4,0),
     received   date default null,
     shipped    date default null,
     primary key (ono),
     foreign key (cno) references customers (cno),
     foreign key (eno) references employees (eno)
    )ENGINE=InnoDB;

create table odetails
    (ono        numeric(4,0),
     pno        numeric(5,0),
     qty        numeric(1,0),
     primary key (ono, pno),
     foreign key (ono) references orders (ono),
     foreign key (pno) references parts (pno)
    )ENGINE=InnoDB;

create table zipcodes
    (zip        numeric(5,0),
     city       varchar(15),
     primary key (zip)
    )ENGINE=InnoDB;

1 个答案:

答案 0 :(得分:0)

1005 - 根据FOREIGN KEYs以正确的顺序声明表格。例如,首先执行zipcodes