0
When executing the error query stating that it is not possible to create the Foreign Keys, I looked in the documentation and did not understand right if this code is possible or not.
create table autor(
cod_autor integer,
nome varchar(50) NOT NULL,
nascimento date NOT NULL,
primary key(cod_autor)
);
create table editora(
cod_editora int,
razao text,
endereco varchar(50),
cnpj int NOT NULL UNIQUE,
cidade varchar(40),
primary key(cod_editora)
);
create table livro(
titulo varchar (100),
cd_autor integer NOT NULL,
cd_editora integer,
valor float NOT NULL,
publicacao DATE not null,
volume INTEGER NOT NULL,
primary key (titulo,cd_autor),
foreign key(cd_autor) references autor(cd_autor) ON UPDATE SET NULL ON DELETE SET NULL,
foreign key (cd_editora) references autor(cd_autor) ON UPDATE SET NULL ON DELETE SET NULL
);
Error :
Cannot add Foreign key Constraint
As for the reference, it was a wrong edition of me in the question before publishing, the error was exactly in
ON UPDATE
andON DELETE
. The tablelivro
has PK:primary key (titulo,cd_autor),
– pic
@pic Also there. If you don’t understand something in the answer, you can ask! ;)
– rbz