My question is very simple but I guess we are all here to support each other and keep learning.
My problem is in this line of code:
INSERT INTO DEPENDIENTES VALUES (78900456,'Oscar','M',15-01-89,'Hijo');
the error bounces me because the number of Certificate 78900456
, already enter it in the previous record.
I guess the solution would be "remove the PK from the DEPENDIENTES Certificate variable, and you're ready to add it", because YES, but it will also allow me to add the same record over and over again.
EYE I CAN ADD THAT ID NUMBER several times, because the person can have several children, BUT NOT ALL THE DATA CAN BE EQUAL "Name_Dep, Sex, DateN, Relationship"
For a moment I also thought about removing the primary key from the TABLE OF PERSONS, but it would not be correct if I did not identify them as unique.?
- Yes or if I have to put as FK to Cedula (DEPENDIENTES) of CEDULA of PERSONS because it is the only way to make the reference.
I hope you can help me because I need to add that last line of code but do not allow me because it's a duplicate value.
NOTE: THERE ARE NO MORE TABLES ARE ONLY THOSE 3
CREATE TABLE DEPARTAMENTOS
(Cod_dep CHAR(2) not null primary key,
Nombre_Dep CHAR(15) not null,
Cedula_Jefe CHAR(8) not null);
CREATE TABLE PERSONAS
(Cedula CHAR(8) not null primary key,
Nombre CHAR(25) not null,
Primer_Apellido CHAR(25) not null,
Segundo_Apellido CHAR(25) not null,
Sexo CHAR(1) CHECK (Sexo IN ('M','F')),
Direccion CHAR(40) not null,
Telefono CHAR(9) not null,
Salario INT not null,
Cedula_Sup CHAR(8) not null,
Cod_dep CHAR(2) not null,
FOREIGN KEY (Cod_dep) REFERENCES DEPARTAMENTOS(Cod_Dep));
CREATE TABLE DEPENDIENTES
(Cedula CHAR(8) not null primary key,
Nombre_Dep CHAR(25) not null,
Sexo CHAR(1) CHECK (Sexo IN ('M','F')),
FechaN DATETIME,
Parentesco CHAR(15) not null,
FOREIGN KEY (Cedula) REFERENCES PERSONAS(Cedula));
INSERT INTO DEPARTAMENTOS VALUES (0,'Gerencia', 43890231);
INSERT INTO DEPARTAMENTOS VALUES (1,'Teleinformatica', 75556734);
INSERT INTO DEPARTAMENTOS VALUES (2,'Desarrollo', 23423445);
INSERT INTO DEPARTAMENTOS VALUES (3,'Soporte Tecnico', 71134534);
INSERT INTO PERSONAS VALUES (71134534,'Juan','Mesa','Uribe','M','Cra 25 22-1','2567532',1600000,23423445,3);
INSERT INTO PERSONAS VALUES (78900456,'Carlos','Betancur','Agudelo','M','Cir. 5 12-5','4445775',1500000,75556743,1);
INSERT INTO PERSONAS VALUES (73456789,'Mario','Gómez','Angel','M','Cr. 53 23-1','3456789',1200000,23423445,2);
INSERT INTO DEPENDIENTES VALUES (78900456,'Juanita','F',12-04-95,'Hija');
INSERT INTO DEPENDIENTES VALUES (78900456,'Oscar','M',15-01-89,'Hijo');