I'm making a somewhat simple database for submitting a job and I'm encountering the same annoying problem.
In the case we have two tables, funcionario[nome,cpf]
and departamento[DNR,CPF do gerente]
. Here is the code:
CREATE SCHEMA empresa;
USE empresa;
CREATE TABLE funcionario (
nome VARCHAR(30),
CPF INT NOT NULL,
DNR INT NOT NULL,
PRIMARY KEY (CPF),
FOREIGN KEY (DNR) REFERENCES DEPARTAMENTO(DNR)
);
CREATE TABLE DEPARTAMENTO
(
CPF INT NOT NULL,
DNR INT NOT NULL,
PRIMARY KEY (DNR),
FOREIGN KEY (CPF) REFERENCES funcionario(CPF)
);
I do not understand why I can not do this. Thank you in advance.