GENERALIZACION
Publicado por Rossana (2 intervenciones) el 25/01/2010 15:48:40
Hola necesito...ayudaaaaaaaa heeeelp, tengo unas tablas de la forma supertipo y subtipo por ejemplo
supertipo: persona(rut, nombre, etc)
subtipo: estudiante
subtipo: profe
la persona puede ser o profe o estudiante, mi gran pregunta es como deberia insertar en este caso aqui dejo el codigo que lo valide mediante un CHECK
CREATE TABLE persona
(
rut varchar(20) NOT NULL PRIMARY KEY,
tipo varchar(30) NOT NULL CHECK(tipo IN ('postulante', 'contratado')),
nombre varchar(45) NOT NULL,
direccion varchar(45)NOT NULL,
mail varchar(30) NOT NULL,
nacionalidad varchar(20) NOT NULL,
edad int NOT NULL,
sexo varchar(10) NOT NULL CHECK (sexo IN ('Hombre','Mujer')),
estado_civil VARCHAR(10) NOT NULL CHECK (estado_civil IN('soltero(a)','casado(a)','viudo(a)', 'separado(a)')),
UNIQUE (rut, tipo)
)
CREATE TABLE contratados
(
rut varchar(20) PRIMARY KEY REFERENCES persona(rut),
tipo varchar(30) NOT NULL CHECK(tipo = 'contratado') DEFAULT 'contratado',
fecha_ingreso_sistema datetime NOT NULL,
fecha_contrato datetime NOT NULL,
fin_contrato DATETIME NOT NULL,
FOREIGN KEY(rut, tipo) REFERENCES persona(rut,
tipo),
UNIQUE (tipo_funcionario)
)
CREATE TABLE postulantes
(
rut varchar(20) PRIMARY KEY REFERENCES persona(rut),
tipo varchar(30) NOT NULL CHECK(tipo = 'postulantes') DEFAULT 'postulante',
fecha_ingreso_sistema datetime NOT NULL,
fecha_contrato datetime NOT NULL,
fin_contrato DATETIME NOT NULL,
FOREIGN KEY(rut, tipo) REFERENCES persona(rut,
tipo),
UNIQUE (tipo_funcionario)
)
supertipo: persona(rut, nombre, etc)
subtipo: estudiante
subtipo: profe
la persona puede ser o profe o estudiante, mi gran pregunta es como deberia insertar en este caso aqui dejo el codigo que lo valide mediante un CHECK
CREATE TABLE persona
(
rut varchar(20) NOT NULL PRIMARY KEY,
tipo varchar(30) NOT NULL CHECK(tipo IN ('postulante', 'contratado')),
nombre varchar(45) NOT NULL,
direccion varchar(45)NOT NULL,
mail varchar(30) NOT NULL,
nacionalidad varchar(20) NOT NULL,
edad int NOT NULL,
sexo varchar(10) NOT NULL CHECK (sexo IN ('Hombre','Mujer')),
estado_civil VARCHAR(10) NOT NULL CHECK (estado_civil IN('soltero(a)','casado(a)','viudo(a)', 'separado(a)')),
UNIQUE (rut, tipo)
)
CREATE TABLE contratados
(
rut varchar(20) PRIMARY KEY REFERENCES persona(rut),
tipo varchar(30) NOT NULL CHECK(tipo = 'contratado') DEFAULT 'contratado',
fecha_ingreso_sistema datetime NOT NULL,
fecha_contrato datetime NOT NULL,
fin_contrato DATETIME NOT NULL,
FOREIGN KEY(rut, tipo) REFERENCES persona(rut,
tipo),
UNIQUE (tipo_funcionario)
)
CREATE TABLE postulantes
(
rut varchar(20) PRIMARY KEY REFERENCES persona(rut),
tipo varchar(30) NOT NULL CHECK(tipo = 'postulantes') DEFAULT 'postulante',
fecha_ingreso_sistema datetime NOT NULL,
fecha_contrato datetime NOT NULL,
fin_contrato DATETIME NOT NULL,
FOREIGN KEY(rut, tipo) REFERENCES persona(rut,
tipo),
UNIQUE (tipo_funcionario)
)
Valora esta pregunta


0