This document contains the database schema for a university student housing system. It includes tables for students, courses, contracts, payments, residences, inspections, and their relationships. Foreign keys linking the tables are then dropped to remove the relationships between the tables in the schema.
3. if exists(select 1 from sys.sysforeignkey where role='FK_CONTRATO_REALIZA_ESTUDIAN') then
alter table CONTRATO
delete foreign key FK_CONTRATO_REALIZA_ESTUDIAN
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_CURSOS_PERTENECE_ESTUDIAN')
then
alter table CURSOS
delete foreign key FK_CURSOS_PERTENECE_ESTUDIAN
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_EMPLEADO_RELATIONS_ESTUDIAN')
then
alter table EMPLEADO
delete foreign key FK_EMPLEADO_RELATIONS_ESTUDIAN
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_ESTUDIAN_ENVIA_FACTURA') then
alter table ESTUDIANTE
delete foreign key FK_ESTUDIAN_ENVIA_FACTURA
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_FACTURA_ENVIA2_ESTUDIAN') then
alter table FACTURA
delete foreign key FK_FACTURA_ENVIA2_ESTUDIAN
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_PAGO_TIENEF_FACTURA') then
alter table PAGO
delete foreign key FK_PAGO_TIENEF_FACTURA
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_PARIENTE_TIENE_ESTUDIAN') then
alter table PARIENTE
delete foreign key FK_PARIENTE_TIENE_ESTUDIAN
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_PISO_RELATIONS_HABITACI') then
alter table PISO
delete foreign key FK_PISO_RELATIONS_HABITACI
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_REALIAZA_REALIAZA_INSPECCI') then
alter table REALIAZA
delete foreign key FK_REALIAZA_REALIAZA_INSPECCI
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_REALIAZA_REALIAZA2_PISO') then
alter table REALIAZA
delete foreign key FK_REALIAZA_REALIAZA2_PISO
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_RESIDENC_PERTENECE_ESTUDIAN')
then
4. alter table RESIDENCIA
delete foreign key FK_RESIDENC_PERTENECE_ESTUDIAN
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='REALIZA_FK'
and t.table_name='CONTRATO'
) then
drop index CONTRATO.REALIZA_FK
end if;
if exists(
select 1 from sys.systable
where table_name='CONTRATO'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table CONTRATO
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='PERTENECE_FK'
and t.table_name='CURSOS'
) then
drop index CURSOS.PERTENECE_FK
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='CURSOS_PK'
and t.table_name='CURSOS'
) then
drop index CURSOS.CURSOS_PK
end if;
if exists(
select 1 from sys.systable
where table_name='CURSOS'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table CURSOS
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='RELATIONSHIP_11_FK'
and t.table_name='EMPLEADO'
) then
drop index EMPLEADO.RELATIONSHIP_11_FK
end if;
5. if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='EMPLEADO_PK'
and t.table_name='EMPLEADO'
) then
drop index EMPLEADO.EMPLEADO_PK
end if;
if exists(
select 1 from sys.systable
where table_name='EMPLEADO'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table EMPLEADO
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='PERTENECER_FK'
and t.table_name='ESTUDIANTE'
) then
drop index ESTUDIANTE.PERTENECER_FK
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='ENVIA_FK'
and t.table_name='ESTUDIANTE'
) then
drop index ESTUDIANTE.ENVIA_FK
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='ESTUDIANTE_PK'
and t.table_name='ESTUDIANTE'
) then
drop index ESTUDIANTE.ESTUDIANTE_PK
end if;
if exists(
select 1 from sys.systable
where table_name='ESTUDIANTE'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table ESTUDIANTE
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='ENVIA2_FK'
6. and t.table_name='FACTURA'
) then
drop index FACTURA.ENVIA2_FK
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='FACTURA_PK'
and t.table_name='FACTURA'
) then
drop index FACTURA.FACTURA_PK
end if;
if exists(
select 1 from sys.systable
where table_name='FACTURA'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table FACTURA
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='HABITACION_PK'
and t.table_name='HABITACION'
) then
drop index HABITACION.HABITACION_PK
end if;
if exists(
select 1 from sys.systable
where table_name='HABITACION'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table HABITACION
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='INSPECCION_PK'
and t.table_name='INSPECCION'
) then
drop index INSPECCION.INSPECCION_PK
end if;
if exists(
select 1 from sys.systable
where table_name='INSPECCION'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table INSPECCION
end if;
7. if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='TIENEF_FK'
and t.table_name='PAGO'
) then
drop index PAGO.TIENEF_FK
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='PAGO_PK'
and t.table_name='PAGO'
) then
drop index PAGO.PAGO_PK
end if;
if exists(
select 1 from sys.systable
where table_name='PAGO'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table PAGO
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='TIENE_FK'
and t.table_name='PARIENTE'
) then
drop index PARIENTE.TIENE_FK
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='PARIENTE_PK'
and t.table_name='PARIENTE'
) then
drop index PARIENTE.PARIENTE_PK
end if;
if exists(
select 1 from sys.systable
where table_name='PARIENTE'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table PARIENTE
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='RELATIONSHIP_8_FK'
8. and t.table_name='PISO'
) then
drop index PISO.RELATIONSHIP_8_FK
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='PISO_PK'
and t.table_name='PISO'
) then
drop index PISO.PISO_PK
end if;
if exists(
select 1 from sys.systable
where table_name='PISO'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table PISO
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='REALIAZA2_FK'
and t.table_name='REALIAZA'
) then
drop index REALIAZA.REALIAZA2_FK
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='REALIAZA_FK'
and t.table_name='REALIAZA'
) then
drop index REALIAZA.REALIAZA_FK
end if;
if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='REALIAZA_PK'
and t.table_name='REALIAZA'
) then
drop index REALIAZA.REALIAZA_PK
end if;
if exists(
select 1 from sys.systable
where table_name='REALIAZA'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table REALIAZA
end if;
9. if exists(
select 1 from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='RESIDENCIA_AK'
and t.table_name='RESIDENCIA'
) then
drop index RESIDENCIA.RESIDENCIA_AK
end if;
if exists(
select 1 from sys.systable
where table_name='RESIDENCIA'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table RESIDENCIA
end if;
/*==============================================================*/
/* Table: CONTRATO */
/*==============================================================*/
create table CONTRATO
(
ID_ESTUDIANTE varchar(10),
NUM_A varchar(5) not null,
TIEMPO varchar(15),
INICIO_ALQ varchar(15),
FINAL_ALQ date,
PERIODO_MIN date
);
/*==============================================================*/
/* Index: REALIZA_FK */
/*==============================================================*/
create index REALIZA_FK on CONTRATO (
ID_ESTUDIANTE ASC
);
/*==============================================================*/
/* Table: CURSOS */
/*==============================================================*/
create table CURSOS
(
NUM_CURSO varchar(5) not null,
ID_ESTUDIANTE varchar(10),
TITULO_CURSO varchar(25),
ID_EMPLEADO varchar(10),
constraint PK_CURSOS primary key (NUM_CURSO)
);
/*==============================================================*/
/* Index: CURSOS_PK */
/*==============================================================*/
create unique index CURSOS_PK on CURSOS (
NUM_CURSO ASC
);
10. /*==============================================================*/
/* Index: PERTENECE_FK */
/*==============================================================*/
create index PERTENECE_FK on CURSOS (
ID_ESTUDIANTE ASC
);
/*==============================================================*/
/* Table: EMPLEADO */
/*==============================================================*/
create table EMPLEADO
(
ID_ESTUDIANTE2 varchar(10) not null,
ID_ESTUDIANTE varchar(10),
NOMBRE_EMPLEADO varchar(25),
APELLIDO_EMPLEADO varchar(25),
FECHA_NAC_EMPLEADO date,
SEXO_EMPLEADO varchar(2),
CATEGORIA_EMPLEADO varchar(30)
constraint CKC_CATEGORIA_EMPLEAD_EMPLEADO check (CATEGORIA_EMPLEADO is
null or (CATEGORIA_EMPLEADO between '30' and '30' and CATEGORIA_EMPLEADO =
lower(CATEGORIA_EMPLEADO))),
constraint PK_EMPLEADO primary key (ID_ESTUDIANTE2)
);
/*==============================================================*/
/* Index: EMPLEADO_PK */
/*==============================================================*/
create unique index EMPLEADO_PK on EMPLEADO (
ID_ESTUDIANTE2 ASC
);
/*==============================================================*/
/* Index: RELATIONSHIP_11_FK */
/*==============================================================*/
create index RELATIONSHIP_11_FK on EMPLEADO (
ID_ESTUDIANTE ASC
);
/*==============================================================*/
/* Table: ESTUDIANTE */
/*==============================================================*/
create table ESTUDIANTE
(
ID_ESTUDIANTE varchar(10) not null,
NUM_FACTURA varchar(5),
NUM_MATRICULA varchar(5) not null,
NOMBRE_ESTUDIANTE varchar(25),
APELLIDO_ESTUDIANTE varchar(25),
FECHA_NAC_EMPLEADO date,
SEXO_EMPLEADO varchar(2),
CATEGORIA_EMPLEADO varchar(30)
constraint CKC_CATEGORIA_EMPLEAD_ESTUDIAN check (CATEGORIA_EMPLEADO is null
or (CATEGORIA_EMPLEADO between '30' and '30' and CATEGORIA_EMPLEADO =
lower(CATEGORIA_EMPLEADO))),
11. NACIONALIDAD varchar(15),
ESTADO_FUMADOR varchar(6),
ESTADO_ACTUAL varchar(15),
CURSO varchar(15),
NECESIDADES varchar(50),
COMENTARIOS varchar(50)
constraint CKC_COMENTARIOS_ESTUDIAN check (COMENTARIOS is null or
(COMENTARIOS between '0' and '30' and COMENTARIOS = lower(COMENTARIOS))),
constraint PK_ESTUDIANTE primary key (ID_ESTUDIANTE)
);
/*==============================================================*/
/* Index: ESTUDIANTE_PK */
/*==============================================================*/
create unique index ESTUDIANTE_PK on ESTUDIANTE (
ID_ESTUDIANTE ASC
);
/*==============================================================*/
/* Index: ENVIA_FK */
/*==============================================================*/
create index ENVIA_FK on ESTUDIANTE (
NUM_FACTURA ASC
);
/*==============================================================*/
/* Index: PERTENECER_FK */
/*==============================================================*/
create index PERTENECER_FK on ESTUDIANTE (
ID_ESTUDIANTE ASC
);
/*==============================================================*/
/* Table: FACTURA */
/*==============================================================*/
create table FACTURA
(
NUM_FACTURA varchar(5) not null,
ID_ESTUDIANTE varchar(10),
NUM_A varchar(5),
SEMESTRE varchar(10),
TIPO_PAGO float,
constraint PK_FACTURA primary key (NUM_FACTURA)
);
/*==============================================================*/
/* Index: FACTURA_PK */
/*==============================================================*/
create unique index FACTURA_PK on FACTURA (
NUM_FACTURA ASC
);
/*==============================================================*/
/* Index: ENVIA2_FK */
/*==============================================================*/
create index ENVIA2_FK on FACTURA (
12. ID_ESTUDIANTE ASC
);
/*==============================================================*/
/* Table: HABITACION */
/*==============================================================*/
create table HABITACION
(
NUM_IDENTIFICACION_HABITACION varchar(5) not null,
NUM_HABITACION integer not null,
IMPORTE_MENSUAL float,
constraint PK_HABITACION primary key (NUM_IDENTIFICACION_HABITACION)
);
/*==============================================================*/
/* Index: HABITACION_PK */
/*==============================================================*/
create unique index HABITACION_PK on HABITACION (
NUM_IDENTIFICACION_HABITACION ASC
);
/*==============================================================*/
/* Table: INSPECCION */
/*==============================================================*/
create table INSPECCION
(
ID_INSPECCION varchar(5) not null,
FECHA_INSPECCION date,
ESTADO_INMUEBLE varchar(15),
COMENTARIOS varchar(50)
constraint CKC_COMENTARIOS_INSPECCI check (COMENTARIOS is null or
(COMENTARIOS between '0' and '30' and COMENTARIOS = lower(COMENTARIOS))),
constraint PK_INSPECCION primary key (ID_INSPECCION)
);
/*==============================================================*/
/* Index: INSPECCION_PK */
/*==============================================================*/
create unique index INSPECCION_PK on INSPECCION (
ID_INSPECCION ASC
);
/*==============================================================*/
/* Table: PAGO */
/*==============================================================*/
create table PAGO
(
NUM_PAGO_FACTURA varchar(5) not null,
NUM_FACTURA varchar(5),
FECHA_PAGO date,
MODO_PAGO varchar(10),
FECHA_RECORDATORIO date,
constraint PK_PAGO primary key (NUM_PAGO_FACTURA)
);
/*==============================================================*/