Oracle: How can I add these constraints?
I made three tables, "investigador", "inv_proy" and "proyecto"
CREATE TABLE INVESTIGADOR (nip number, nombre varchar(20),
apellido varchar(20), fecha_nac date, sexo char, dir varchar(20), correo varchar(50));
CREATE TABLE PROYECTO (id number, descripcion varchar(50), duración number, fecha_inicio date, presupuesto number);
CREATE TABLE INV_PROY (nip number, id number, fecha date, cargo varchar(20));
ALTER TABLE INV_PROY ADD CONSTRAINTS INV_PROY_PK PRIMARY KEY (NIP);
ALTER TABLE INVESTIGADOR ADD CONSTRAINTS INVESTIGADOR_PK PRIMARY KEY (NIP);
AL开发者_运维百科TER TABLE PROYECTO ADD CONSTRAINTS PROYECTO_PK PRIMARY KEY(ID);
How can I make it so each time I add a register to INV_PROY there is both an associated INVESTIGADOR and a PROYECTO register?
And how can I make it so that each time I erase a register from INVESTIGADOR it's also erased from its associate tables?
It's difficult to answer your question without knowing how the three tables are related but the common answer is to use foreign key constraints with cascading deletes.
精彩评论