Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL表创建错误_Mysql_Sql_Unique_Primary Key_Create Table - Fatal编程技术网

MySQL表创建错误

MySQL表创建错误,mysql,sql,unique,primary-key,create-table,Mysql,Sql,Unique,Primary Key,Create Table,我想创建一个日期表(葡萄牙语数据),我在dia(天)、mes(月)和ano(年)前面有“unique”属性,但我决定删除它们,因为这没有意义,因为表中可能有很多天“25”和很多“1月”,但当我删除“unique”属性时,我得到了以下错误 错误1005(HY000):无法创建表“ist169515.Disponivel”(错误号:150) 错误1005(HY000):无法创建表“ist169515.Venda”(错误号:150) 查询正常,0行受影响(0.07秒) 错误1005(HY000):无法

我想创建一个日期表(葡萄牙语数据),我在dia(天)、mes(月)和ano(年)前面有“unique”属性,但我决定删除它们,因为这没有意义,因为表中可能有很多天“25”和很多“1月”,但当我删除“unique”属性时,我得到了以下错误

错误1005(HY000):无法创建表“ist169515.Disponivel”(错误号:150)
错误1005(HY000):无法创建表“ist169515.Venda”(错误号:150)
查询正常,0行受影响(0.07秒)
错误1005(HY000):无法创建表“ist169515.Encomenda”(错误号:150)
错误1005(HY000):无法创建表“ist169515.RegistoEnc”(错误号:150)

完整代码如下所示:

create table Alimento
    (nomeA varchar(80) not null unique,
    vegetariano boolean not null,
    PRIMARY KEY(nomeA));

create table Simples
        (nomeA varchar(80) not null,
    calgramas numeric(5,2) not null,
    tipo varchar(255) not null,
    PRIMARY KEY(nomeA),
    FOREIGN KEY(nomeA) REFERENCES Alimento(nomeA));


create table Agregado
        (nomeA varchar(80) not null,
    calorias numeric(5,2) not null,
    PRIMARY KEY(nomeA),
    FOREIGN KEY(nomeA) REFERENCES Alimento(nomeA));

create table Composto
    (nomeAgg varchar(80) not null unique,
    nomeS varchar (80) not null unique,
    quantidade numeric(4),
    PRIMARY KEY(nomeAgg, nomeS),
    FOREIGN KEY(nomeAgg) REFERENCES Agregado(nomeA),
    FOREIGN KEY(nomeS) REFERENCES Simples(nomeA));

create table Prato
    (nomeA varchar(80) not null,
     preco numeric(5,2) not null,
     PRIMARY KEY(nomeA),
     FOREIGN KEY(nomeA) REFERENCES Alimento(nomeA));

create table Restaurante
     (nomeR varchar(80) not null unique,
      PRIMARY KEY(nomeR));

create table Data
     (dia numeric(2) not null,
     mes varchar(45) not null,
     ano numeric(4) not null,
     PRIMARY KEY(dia, mes, ano));

create table Disponivel
     (nomeA varchar(80) not null,
     nomeR varchar(80) not null,
     dia numeric(2) not null,
     mes varchar(45) not null,
     ano numeric(4) not null,
     PRIMARY KEY(nomeA, nomeR, dia, mes, ano),
     FOREIGN KEY(nomeA) REFERENCES Prato(nomeA),
     FOREIGN KEY(nomeR) REFERENCES Restaurante(nomeR),
     FOREIGN KEY(dia) REFERENCES Data(dia),
     FOREIGN KEY(mes) REFERENCES Data(mes),
     FOREIGN KEY(ano) REFERENCES Data(ano));

create table Venda
     (nomeA varchar(80) not null,
     dia numeric(2) not null,
     mes varchar(45) not null,
     ano numeric(4) not null,
     nomeR varchar(80) not null,
     num numeric(5) not null,
     PRIMARY KEY(nomeA, dia, mes, ano, nomeR),
     FOREIGN KEY(nomeA) REFERENCES Prato(nomeA),
     FOREIGN KEY(dia) REFERENCES Data(dia),
     FOREIGN KEY(mes) REFERENCES Data(mes),
     FOREIGN KEY(ano) REFERENCES Data(ano),
     FOREIGN KEY(nomeR) REFERENCES Restaurante(nomeR));

 create table Cliente
     (email varchar(255) not null unique,
     PRIMARY KEY Cliente(email));

 create table Encomenda
     (email varchar(255) not null,
     nEnc numeric(5) not null unique,
     precoTotal numeric(5,2) not null,
     desconto double(20,2) not null,
     nomeR varchar(80) not null,
     dia numeric(2) not null,
     mes varchar(45) not null,
     ano numeric(4) not null,
     PRIMARY KEY(email, nEnc),
     FOREIGN KEY(email) REFERENCES Cliente(email),
     FOREIGN KEY(nomeR) REFERENCES Restaurante(nomeR),
     FOREIGN KEY(dia) REFERENCES Data(dia),
     FOREIGN KEY(mes) REFERENCES Data(mes),
     FOREIGN KEY(ano) REFERENCES Data(ano));

  create table RegistoEnc
     (email varchar(255) not null,
     nEnc numeric(5) not null,
     nomeA varchar(80) not null,
     PRIMARY KEY(email, nEnc, nomeA),
     FOREIGN KEY(email) REFERENCES Encomenda(email),
     FOREIGN KEY(nEnc) REFERENCES Encomenda(nEnc),
     FOREIGN KEY(nomeA) REFERENCES Prato(nomeA));
编辑:

而不是

 FOREIGN KEY(dia) REFERENCES Data(dia),
 FOREIGN KEY(mes) REFERENCES Data(mes),
 FOREIGN KEY(ano) REFERENCES Data(ano),

Prato
restaurant
是否存在?是的,我只是引用了出现问题的表,将放入完整的代码否,我删除了旧数据库,创建了一个新数据库,只是为了确定,它给了我一个错误。是外键与主键不代表相同的内容。3(dia、mes、ano)的组合是主键,您分别说明了它们。干杯
 FOREIGN KEY(dia) REFERENCES Data(dia),
 FOREIGN KEY(mes) REFERENCES Data(mes),
 FOREIGN KEY(ano) REFERENCES Data(ano),