2
I’m making a database rather simple for presentation of a work and I’m finding the same annoying problem.
In this 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 don’t understand why I can’t do this. Thank you in advance.
Welcome to Stackoverflow Pedro. I made some changes to improve the view, any problem you can reverse edits through of this link.
– Renan Gomes
I just don’t understand why a department has a key in Employee. This creates a 1-1 ratio, meaning a department can only have one employee. Maybe the key just needs to be on the job. Creating an Employee Relationship belongs to a department and a department owns N employees.
– gmsantos