Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*==============================================================*/
- /* DBMS name: PostgreSQL 9.x */
- /* Created on: 26-09-2014 0:15:49 */
- /*==============================================================*/
- drop index comuna_pertenece_a_provincia_fk;
- drop index comuna_pk;
- drop table comuna;
- drop index hospital_tiene_comuna_fk;
- drop index info_hospital_pk;
- drop table info_hospital;
- drop index provincia_pertenece_a_region_fk;
- drop index provincia_pk;
- drop table provincia;
- drop index region_pk;
- drop table region;
- /*==============================================================*/
- /* Table: info_hospital */
- /*==============================================================*/
- create table info_hospital (
- hospital_id int4 not null default 1,
- region_id int4 not null,
- comuna_id int4 not null,
- provincia_id int4 not null,
- hospital_nombre varchar(255) not null,
- hospital_telefono int4 not null,
- hospital_email varchar(255) not null,
- constraint pk_info_hospital primary key (hospital_id)
- );
- /*==============================================================*/
- /* Index: info_hospital_pk */
- /*==============================================================*/
- create unique index info_hospital_pk on info_hospital (
- hospital_id
- );
- /*==============================================================*/
- /* Index: hospital_tiene_comuna_fk */
- /*==============================================================*/
- create index hospital_tiene_comuna_fk on info_hospital (
- comuna_id
- );
- /*==============================================================*/
- /* Index: hospital_tiene_region_fk */
- /*==============================================================*/
- create index hospital_tiene_region_fk on info_hospital (
- region_id
- );
- /*==============================================================*/
- /* Index: hospital_tiene_provincia_fk */
- /*==============================================================*/
- create index hospital_tiene_provincia_fk on info_hospital (
- provincia_id
- );
- /*==============================================================*/
- /* Table: provincia */
- /*==============================================================*/
- create table provincia (
- provincia_id int4 not null,
- region_id int4 not null,
- provincia_nombre varchar(23) not null,
- constraint pk_provincia primary key (provincia_id)
- );
- /*==============================================================*/
- /* Index: provincia_pk */
- /*==============================================================*/
- create unique index provincia_pk on provincia (
- provincia_id
- );
- /*==============================================================*/
- /* Index: provincia_pertenece_a_region_fk */
- /*==============================================================*/
- create index provincia_pertenece_a_region_fk on provincia (
- region_id
- );
- /*==============================================================*/
- /* Table: region */
- /*==============================================================*/
- create table region (
- region_id int4 not null,
- region_nombre varchar(50) not null,
- constraint pk_region primary key (region_id)
- );
- /*==============================================================*/
- /* Index: region_pk */
- /*==============================================================*/
- create unique index region_pk on region (
- region_id
- );
- /*==============================================================*/
- /* Table: comuna */
- /*==============================================================*/
- create table comuna (
- comuna_id int4 not null,
- provincia_id int4 not null,
- comuna_nombre varchar(20) not null,
- constraint pk_comuna primary key (comuna_id)
- );
- /*==============================================================*/
- /* Index: comuna_pk */
- /*==============================================================*/
- create unique index comuna_pk on comuna (
- comuna_id
- );
- /*==============================================================*/
- /* Index: comuna_pertenece_a_provincia_fk */
- /*==============================================================*/
- create index comuna_pertenece_a_provincia_fk on comuna (
- provincia_id
- );
- alter table comuna
- add constraint provincia_fk foreign key (provincia_id)
- references provincia (provincia_id)
- on delete cascade on update cascade;
- alter table comuna
- add constraint provincia_fk foreign key (provincia_id)
- references provincia (provincia_id)
- on delete cascade on update cascade;
- alter table info_hospital
- add constraint info_hospital_comuna_fk foreign key (comuna_id)
- references comuna (comuna_id)
- on delete cascade on update cascade;
- alter table info_hospital
- add constraint info_hospital_provincia_fk foreign key (provincia_id)
- references provincia (provincia_id)
- on delete cascade on update cascade;
- alter table info_hospital
- add constraint info_hospital_region_fk foreign key (region_id)
- references region (region_id)
- on delete cascade on update cascade;
- alter table provincia
- add constraint region_fk foreign key (region_id)
- references region (region_id)
- on delete cascade on update cascade;
- alter table provincia
- add constraint region_fk foreign key (region_id)
- references region (region_id)
- on delete cascade on update cascade;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement