-- D:\\DDL\\postgresql\\schema-013.sql\012--\012-- Generated for ANSI SQL92 on Fri Dec 21  17:59:34 2007 by Server Generator 10.1.2.6.18\012------------------------------------------------------------------------------------\012--\012--  Post-Generation Modifications:\012--\012--  1. Changed domain FILE from BIT(32000) to BYTEA\012--  2. Changed domain TECH_ID from NUMERIC(20) to BIGINT\012--  3. Changed domain BOOLEAN_CHAR from CHAR(1) DEFAULT F to BOOLEAN DEFAULT FALSE\012--  4. Removed the check constraint AVCON_1197023825_IS_MA_000 CHECK from the\012--     table MATERIAL_TYPE_PROPERTY_TYPES as it is only needed in Oracle\012--  5. Added the ON DELETE CASCADE qualifier to the foreign key MAPR_MTPT_FK of\012--     the MATERIAL_PROPERTIES table\012--  6. Added the Sequence, Index and Trigger sections\012------------------------------------------------------------------------------------\012\012-- Creating domains\012\012CREATE DOMAIN BOOLEAN_CHAR AS BOOLEAN DEFAULT FALSE;\012CREATE DOMAIN CODE AS VARCHAR(20);\012CREATE DOMAIN COLUMN_LABEL AS VARCHAR(40);\012CREATE DOMAIN DESCRIPTION_250 AS VARCHAR(250);\012CREATE DOMAIN DESCRIPTION_80 AS VARCHAR(80);\012CREATE DOMAIN DOUBLE_PRECISION_VALUE AS DOUBLE PRECISION;\012CREATE DOMAIN FILE AS BYTEA;\012CREATE DOMAIN FILE_NAME AS VARCHAR(100);\012CREATE DOMAIN GENERIC_VALUE AS VARCHAR(1024);\012CREATE DOMAIN OBJECT_NAME AS VARCHAR(50);\012CREATE DOMAIN REAL_VALUE AS REAL;\012CREATE DOMAIN TECH_ID AS BIGINT;\012CREATE DOMAIN TIME_STAMP AS TIMESTAMP DEFAULT CURRENT_TIMESTAMP;\012CREATE DOMAIN USER_ID AS VARCHAR(20);\012\012-- Creating tables\012\012CREATE TABLE DATA (ID TECH_ID NOT NULL,REGISTRATION_TIMESTAMP TIME_STAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,OBTY_ID TECH_ID NOT NULL,PROC_ID_ACQUIRED_BY TECH_ID NOT NULL,SAMP_ID_ACQUIRED_FROM TECH_ID,SAMP_ID_DERIVED_FROM TECH_ID);\012CREATE TABLE DATA_TYPES (ID TECH_ID NOT NULL,CODE CODE NOT NULL,DESCRIPTION DESCRIPTION_80 NOT NULL);\012CREATE TABLE DATA_VALUES (ID TECH_ID NOT NULL,DATA_ID TECH_ID NOT NULL,SACO_ID TECH_ID NOT NULL,VALUE DOUBLE_PRECISION_VALUE NOT NULL);\012CREATE TABLE EXPERIMENTS (ID TECH_ID NOT NULL,CODE CODE NOT NULL,EXTY_ID TECH_ID NOT NULL,MATE_ID_STUDY_OBJECT TECH_ID,PERS_ID_REGISTERER TECH_ID,REGISTRATION_TIMESTAMP TIME_STAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,DESCRIPTION DESCRIPTION_250,PROJ_ID TECH_ID NOT NULL);\012CREATE TABLE EXPERIMENT_ATTACHMENTS (ID TECH_ID NOT NULL,EXPE_ID TECH_ID NOT NULL,FILE_NAME FILE_NAME NOT NULL,REGISTRATION_TIMESTAMP TIME_STAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,VALUE FILE NOT NULL,VERSION INTEGER NOT NULL,PERS_ID_REGISTERER TECH_ID NOT NULL);\012CREATE TABLE EXPERIMENT_TYPES (ID TECH_ID NOT NULL,CODE CODE NOT NULL,DESCRIPTION DESCRIPTION_80);\012CREATE TABLE EXTERNAL_DATA (DATA_ID TECH_ID NOT NULL,LOCATION VARCHAR(200) NOT NULL,LOTY_ID TECH_ID NOT NULL,FFTY_ID TECH_ID NOT NULL);\012CREATE TABLE FILE_FORMAT_TYPES (ID TECH_ID NOT NULL,CODE CODE NOT NULL,DESCRIPTION DESCRIPTION_80);\012CREATE TABLE INVALIDATIONS (ID TECH_ID NOT NULL,PERS_ID_REGISTERER TECH_ID NOT NULL,REGISTRATION_TIMESTAMP TIME_STAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,REASON DESCRIPTION_250);\012CREATE TABLE LOCATOR_TYPES (ID TECH_ID NOT NULL,CODE CODE NOT NULL,DESCRIPTION DESCRIPTION_80);\012CREATE TABLE MATERIALS (ID TECH_ID NOT NULL,CODE CODE NOT NULL,MATY_ID TECH_ID NOT NULL,REGISTRATION_TIMESTAMP TIME_STAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,PERS_ID_REGISTERER TECH_ID NOT NULL,MATE_ID_INHIBITOR_OF TECH_ID);\012CREATE TABLE MATERIAL_BATCHES (ID TECH_ID NOT NULL,CODE CODE NOT NULL,AMOUNT REAL_VALUE,MATE_ID TECH_ID NOT NULL,PROC_ID TECH_ID,REGISTRATION_TIMESTAMP TIME_STAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,PERS_ID_REGISTERER TECH_ID NOT NULL);\012CREATE TABLE MATERIAL_PROPERTIES (ID TECH_ID NOT NULL,MATE_ID TECH_ID NOT NULL,MTPT_ID TECH_ID NOT NULL,VALUE GENERIC_VALUE NOT NULL,REGISTRATION_TIMESTAMP TIME_STAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,PERS_ID_REGISTERER TECH_ID NOT NULL);\012CREATE TABLE MATERIAL_TYPES (ID TECH_ID NOT NULL,CODE CODE NOT NULL,DESCRIPTION DESCRIPTION_80);\012CREATE TABLE MATERIAL_TYPE_PROPERTY_TYPES (ID TECH_ID NOT NULL,MATY_ID TECH_ID NOT NULL,PRTY_ID TECH_ID NOT NULL,IS_MANDATORY BOOLEAN_CHAR NOT NULL DEFAULT 'F',REGISTRATION_TIMESTAMP TIME_STAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,PERS_ID_REGISTERER TECH_ID NOT NULL);\012CREATE TABLE OBSERVABLE_TYPES (ID TECH_ID NOT NULL,CODE CODE NOT NULL,DESCRIPTION DESCRIPTION_80);\012CREATE TABLE ORGANIZATIONS (ID TECH_ID NOT NULL,CODE CODE NOT NULL);\012CREATE TABLE PERSONS (ID TECH_ID NOT NULL,FIRST_NAME VARCHAR(30),LAST_NAME VARCHAR(30),USER_ID USER_ID,EMAIL OBJECT_NAME);\012CREATE TABLE PROCEDURES (ID TECH_ID NOT NULL,REGISTRATION_TIMESTAMP TIME_STAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,EXPE_ID TECH_ID NOT NULL,PCTY_ID TECH_ID NOT NULL,PERS_ID TECH_ID);\012CREATE TABLE PROCEDURE_TYPES (ID TECH_ID NOT NULL,CODE CODE NOT NULL,DESCRIPTION DESCRIPTION_80 NOT NULL);\012CREATE TABLE PROJECTS (ID TECH_ID NOT NULL,CODE CODE NOT NULL,ORGA_ID TECH_ID NOT NULL);\012CREATE TABLE PROPERTY_TYPES (ID TECH_ID NOT NULL,CODE CODE NOT NULL,DESCRIPTION DESCRIPTION_80 NOT NULL,LABEL COLUMN_LABEL NOT NULL,DATY_ID TECH_ID NOT NULL,REGISTRATION_TIMESTAMP TIME_STAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,PERS_ID_REGISTERER TECH_ID NOT NULL);\012CREATE TABLE SAMPLES (ID TECH_ID NOT NULL,CODE CODE NOT NULL,SAMP_ID_TOP TECH_ID,SAMP_ID_GENERATED_FROM TECH_ID,SATY_ID TECH_ID NOT NULL,REGISTRATION_TIMESTAMP TIME_STAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,PERS_ID_REGISTERER TECH_ID NOT NULL,INVA_ID TECH_ID);\012CREATE TABLE SAMPLE_COMPONENTS (ID TECH_ID NOT NULL,CODE CODE NOT NULL,SAMP_ID TECH_ID NOT NULL);\012CREATE TABLE SAMPLE_COMPONENT_MATERIALS (ID TECH_ID NOT NULL,SACO_ID TECH_ID NOT NULL,MABA_ID TECH_ID NOT NULL);\012CREATE TABLE SAMPLE_INPUTS (ID TECH_ID NOT NULL,SAMP_ID TECH_ID NOT NULL,PROC_ID TECH_ID NOT NULL);\012CREATE TABLE SAMPLE_TYPES (ID TECH_ID NOT NULL,CODE CODE NOT NULL,DESCRIPTION DESCRIPTION_80);\012\012-- Creating primary key constraints\012\012ALTER TABLE DATA ADD CONSTRAINT DATA_PK PRIMARY KEY(ID);\012ALTER TABLE DATA_TYPES ADD CONSTRAINT DATY_PK PRIMARY KEY(ID);\012ALTER TABLE DATA_VALUES ADD CONSTRAINT DAVA_PK PRIMARY KEY(ID);\012ALTER TABLE EXPERIMENTS ADD CONSTRAINT EXPE_PK PRIMARY KEY(ID);\012ALTER TABLE EXPERIMENT_ATTACHMENTS ADD CONSTRAINT EXAT_PK PRIMARY KEY(ID);\012ALTER TABLE EXPERIMENT_TYPES ADD CONSTRAINT EXTY_PK PRIMARY KEY(ID);\012ALTER TABLE EXTERNAL_DATA ADD CONSTRAINT EXDA_PK PRIMARY KEY(DATA_ID);\012ALTER TABLE FILE_FORMAT_TYPES ADD CONSTRAINT FFTY_PK PRIMARY KEY(ID);\012ALTER TABLE INVALIDATIONS ADD CONSTRAINT INVA_PK PRIMARY KEY(ID);\012ALTER TABLE LOCATOR_TYPES ADD CONSTRAINT LOTY_PK PRIMARY KEY(ID);\012ALTER TABLE MATERIALS ADD CONSTRAINT MATE_PK PRIMARY KEY(ID);\012ALTER TABLE MATERIAL_BATCHES ADD CONSTRAINT MABA_PK PRIMARY KEY(ID);\012ALTER TABLE MATERIAL_PROPERTIES ADD CONSTRAINT MAPR_PK PRIMARY KEY(ID);\012ALTER TABLE MATERIAL_TYPES ADD CONSTRAINT MATY_PK PRIMARY KEY(ID);\012ALTER TABLE MATERIAL_TYPE_PROPERTY_TYPES ADD CONSTRAINT MTPT_PK PRIMARY KEY(ID);\012ALTER TABLE OBSERVABLE_TYPES ADD CONSTRAINT OBTY_PK PRIMARY KEY(ID);\012ALTER TABLE ORGANIZATIONS ADD CONSTRAINT ORGA_PK PRIMARY KEY(ID);\012ALTER TABLE PERSONS ADD CONSTRAINT PERS_PK PRIMARY KEY(ID);\012ALTER TABLE PROCEDURES ADD CONSTRAINT PROC_PK PRIMARY KEY(ID);\012ALTER TABLE PROCEDURE_TYPES ADD CONSTRAINT PCTY_PK PRIMARY KEY(ID);\012ALTER TABLE PROJECTS ADD CONSTRAINT PROJ_PK PRIMARY KEY(ID);\012ALTER TABLE PROPERTY_TYPES ADD CONSTRAINT PRTY_PK PRIMARY KEY(ID);\012ALTER TABLE SAMPLES ADD CONSTRAINT SAMP_PK PRIMARY KEY(ID);\012ALTER TABLE SAMPLE_COMPONENTS ADD CONSTRAINT SACO_PK PRIMARY KEY(ID);\012ALTER TABLE SAMPLE_COMPONENT_MATERIALS ADD CONSTRAINT SCMA_PK PRIMARY KEY(ID);\012ALTER TABLE SAMPLE_INPUTS ADD CONSTRAINT SAIN_PK PRIMARY KEY(ID);\012ALTER TABLE SAMPLE_TYPES ADD CONSTRAINT SATY_PK PRIMARY KEY(ID);\012\012-- Creating unique constraints\012\012ALTER TABLE DATA_TYPES ADD CONSTRAINT DATY_BK_UK UNIQUE(CODE);\012ALTER TABLE DATA_VALUES ADD CONSTRAINT DAVA_BK_UK UNIQUE(DATA_ID,SACO_ID);\012ALTER TABLE EXPERIMENTS ADD CONSTRAINT EXPE_BK_UK UNIQUE(CODE,PROJ_ID);\012ALTER TABLE EXPERIMENT_ATTACHMENTS ADD CONSTRAINT EXAT_BK_UK UNIQUE(EXPE_ID,FILE_NAME,VERSION);\012ALTER TABLE EXPERIMENT_TYPES ADD CONSTRAINT EXTY_BK_UK UNIQUE(CODE);\012ALTER TABLE EXTERNAL_DATA ADD CONSTRAINT EXDA_BK_UK UNIQUE(LOCATION);\012ALTER TABLE FILE_FORMAT_TYPES ADD CONSTRAINT FFTY_BK_UK UNIQUE(CODE);\012ALTER TABLE LOCATOR_TYPES ADD CONSTRAINT LOTY_BK_UK UNIQUE(CODE);\012ALTER TABLE MATERIALS ADD CONSTRAINT MATE_BK_UK UNIQUE(CODE,MATY_ID);\012ALTER TABLE MATERIAL_BATCHES ADD CONSTRAINT MABA_BK_UK UNIQUE(CODE,MATE_ID);\012ALTER TABLE MATERIAL_PROPERTIES ADD CONSTRAINT MAPR_BK_UK UNIQUE(MATE_ID,MTPT_ID);\012ALTER TABLE MATERIAL_TYPES ADD CONSTRAINT MATY_BK_UK UNIQUE(CODE);\012ALTER TABLE MATERIAL_TYPE_PROPERTY_TYPES ADD CONSTRAINT MTPT_BK_UK UNIQUE(MATY_ID,PRTY_ID);\012ALTER TABLE OBSERVABLE_TYPES ADD CONSTRAINT OBTY_BK_UK UNIQUE(CODE);\012ALTER TABLE ORGANIZATIONS ADD CONSTRAINT ORGA_BK_UK UNIQUE(CODE);\012ALTER TABLE PERSONS ADD CONSTRAINT PERS_BK_UK UNIQUE(USER_ID);\012ALTER TABLE PROCEDURE_TYPES ADD CONSTRAINT PCTY_BK_UK UNIQUE(CODE);\012ALTER TABLE PROJECTS ADD CONSTRAINT PROJ_BK_UK UNIQUE(CODE,ORGA_ID);\012ALTER TABLE PROPERTY_TYPES ADD CONSTRAINT PRTY_BK_UK UNIQUE(CODE);\012ALTER TABLE SAMPLES ADD CONSTRAINT SAMP_BK_UK UNIQUE(CODE);\012ALTER TABLE SAMPLE_COMPONENTS ADD CONSTRAINT SACO_BK_UK UNIQUE(CODE,SAMP_ID);\012ALTER TABLE SAMPLE_COMPONENT_MATERIALS ADD CONSTRAINT SCMA_BK_UK UNIQUE(MABA_ID,SACO_ID);\012ALTER TABLE SAMPLE_INPUTS ADD CONSTRAINT SAIN_BK_UK UNIQUE(SAMP_ID,PROC_ID);\012ALTER TABLE SAMPLE_TYPES ADD CONSTRAINT SATY_BK_UK UNIQUE(CODE);\012\012-- Creating foreign key constraints\012\012ALTER TABLE DATA ADD CONSTRAINT DATA_OBTY_FK FOREIGN KEY (OBTY_ID) REFERENCES OBSERVABLE_TYPES(ID);\012ALTER TABLE DATA ADD CONSTRAINT DATA_PROC_FK FOREIGN KEY (PROC_ID_ACQUIRED_BY) REFERENCES PROCEDURES(ID);\012ALTER TABLE DATA ADD CONSTRAINT DATA_SAMP_DERIVED_FROM_FK FOREIGN KEY (SAMP_ID_DERIVED_FROM) REFERENCES SAMPLES(ID);\012ALTER TABLE DATA ADD CONSTRAINT DATA_SAMP_FK FOREIGN KEY (SAMP_ID_ACQUIRED_FROM) REFERENCES SAMPLES(ID);\012ALTER TABLE DATA_VALUES ADD CONSTRAINT DAVA_DATA_FK FOREIGN KEY (DATA_ID) REFERENCES DATA(ID);\012ALTER TABLE DATA_VALUES ADD CONSTRAINT DAVA_SACO_FK FOREIGN KEY (SACO_ID) REFERENCES SAMPLE_COMPONENTS(ID);\012ALTER TABLE EXPERIMENTS ADD CONSTRAINT EXPE_EXTY_FK FOREIGN KEY (EXTY_ID) REFERENCES EXPERIMENT_TYPES(ID);\012ALTER TABLE EXPERIMENTS ADD CONSTRAINT EXPE_MATE_FK FOREIGN KEY (MATE_ID_STUDY_OBJECT) REFERENCES MATERIALS(ID);\012ALTER TABLE EXPERIMENTS ADD CONSTRAINT EXPE_PERS_FK FOREIGN KEY (PERS_ID_REGISTERER) REFERENCES PERSONS(ID);\012ALTER TABLE EXPERIMENTS ADD CONSTRAINT EXPE_PROJ_FK FOREIGN KEY (PROJ_ID) REFERENCES PROJECTS(ID);\012ALTER TABLE EXPERIMENT_ATTACHMENTS ADD CONSTRAINT EXAT_EXPE_FK FOREIGN KEY (EXPE_ID) REFERENCES EXPERIMENTS(ID);\012ALTER TABLE EXPERIMENT_ATTACHMENTS ADD CONSTRAINT EXAT_PERS_FK FOREIGN KEY (PERS_ID_REGISTERER) REFERENCES PERSONS(ID);\012ALTER TABLE EXTERNAL_DATA ADD CONSTRAINT EXDA_DATA_FK FOREIGN KEY (DATA_ID) REFERENCES DATA(ID);\012ALTER TABLE EXTERNAL_DATA ADD CONSTRAINT EXDA_FFTY_FK FOREIGN KEY (FFTY_ID) REFERENCES FILE_FORMAT_TYPES(ID);\012ALTER TABLE EXTERNAL_DATA ADD CONSTRAINT EXDA_LOTY_FK FOREIGN KEY (LOTY_ID) REFERENCES LOCATOR_TYPES(ID);\012ALTER TABLE INVALIDATIONS ADD CONSTRAINT INVA_PERS_FK FOREIGN KEY (PERS_ID_REGISTERER) REFERENCES PERSONS(ID);\012ALTER TABLE MATERIALS ADD CONSTRAINT MATE_MATE_FK FOREIGN KEY (MATE_ID_INHIBITOR_OF) REFERENCES MATERIALS(ID);\012ALTER TABLE MATERIALS ADD CONSTRAINT MATE_MATY_FK FOREIGN KEY (MATY_ID) REFERENCES MATERIAL_TYPES(ID);\012ALTER TABLE MATERIALS ADD CONSTRAINT MATE_PERS_FK FOREIGN KEY (PERS_ID_REGISTERER) REFERENCES PERSONS(ID);\012ALTER TABLE MATERIAL_BATCHES ADD CONSTRAINT MABA_MATE_FK FOREIGN KEY (MATE_ID) REFERENCES MATERIALS(ID);\012ALTER TABLE MATERIAL_BATCHES ADD CONSTRAINT MABA_PERS_FK FOREIGN KEY (PERS_ID_REGISTERER) REFERENCES PERSONS(ID);\012ALTER TABLE MATERIAL_BATCHES ADD CONSTRAINT MABA_PROC_FK FOREIGN KEY (PROC_ID) REFERENCES PROCEDURES(ID);\012ALTER TABLE MATERIAL_PROPERTIES ADD CONSTRAINT MAPR_MATE_FK FOREIGN KEY (MATE_ID) REFERENCES MATERIALS(ID);\012ALTER TABLE MATERIAL_PROPERTIES ADD CONSTRAINT MAPR_MTPT_FK FOREIGN KEY (MTPT_ID) REFERENCES MATERIAL_TYPE_PROPERTY_TYPES(ID) ON DELETE CASCADE;\012ALTER TABLE MATERIAL_PROPERTIES ADD CONSTRAINT MAPR_PERS_FK FOREIGN KEY (PERS_ID_REGISTERER) REFERENCES PERSONS(ID);\012ALTER TABLE MATERIAL_TYPE_PROPERTY_TYPES ADD CONSTRAINT MTPT_MATY_FK FOREIGN KEY (MATY_ID) REFERENCES MATERIAL_TYPES(ID);\012ALTER TABLE MATERIAL_TYPE_PROPERTY_TYPES ADD CONSTRAINT MTPT_PERS_FK FOREIGN KEY (PERS_ID_REGISTERER) REFERENCES PERSONS(ID);\012ALTER TABLE MATERIAL_TYPE_PROPERTY_TYPES ADD CONSTRAINT MTPT_PRTY_FK FOREIGN KEY (PRTY_ID) REFERENCES PROPERTY_TYPES(ID);\012ALTER TABLE PROCEDURES ADD CONSTRAINT PROC_EXPE_FK FOREIGN KEY (EXPE_ID) REFERENCES EXPERIMENTS(ID);\012ALTER TABLE PROCEDURES ADD CONSTRAINT PROC_PCTY_FK FOREIGN KEY (PCTY_ID) REFERENCES PROCEDURE_TYPES(ID);\012ALTER TABLE PROCEDURES ADD CONSTRAINT PROC_PERS_FK FOREIGN KEY (PERS_ID) REFERENCES PERSONS(ID);\012ALTER TABLE PROJECTS ADD CONSTRAINT PROJ_ORGA_FK FOREIGN KEY (ORGA_ID) REFERENCES ORGANIZATIONS(ID);\012ALTER TABLE PROPERTY_TYPES ADD CONSTRAINT PRTY_DATY_FK FOREIGN KEY (DATY_ID) REFERENCES DATA_TYPES(ID);\012ALTER TABLE PROPERTY_TYPES ADD CONSTRAINT PRTY_PERS_FK FOREIGN KEY (PERS_ID_REGISTERER) REFERENCES PERSONS(ID);\012ALTER TABLE SAMPLES ADD CONSTRAINT SAMP_INVA_FK FOREIGN KEY (INVA_ID) REFERENCES INVALIDATIONS(ID);\012ALTER TABLE SAMPLES ADD CONSTRAINT SAMP_PERS_FK FOREIGN KEY (PERS_ID_REGISTERER) REFERENCES PERSONS(ID);\012ALTER TABLE SAMPLES ADD CONSTRAINT SAMP_SAMP_FK_GENERATED_FROM FOREIGN KEY (SAMP_ID_GENERATED_FROM) REFERENCES SAMPLES(ID);\012ALTER TABLE SAMPLES ADD CONSTRAINT SAMP_SAMP_FK_TOP FOREIGN KEY (SAMP_ID_TOP) REFERENCES SAMPLES(ID);\012ALTER TABLE SAMPLES ADD CONSTRAINT SAMP_SATY_FK FOREIGN KEY (SATY_ID) REFERENCES SAMPLE_TYPES(ID);\012ALTER TABLE SAMPLE_COMPONENTS ADD CONSTRAINT SACO_SAMP_FK FOREIGN KEY (SAMP_ID) REFERENCES SAMPLES(ID);\012ALTER TABLE SAMPLE_COMPONENT_MATERIALS ADD CONSTRAINT SCMA_MABA_FK FOREIGN KEY (MABA_ID) REFERENCES MATERIAL_BATCHES(ID);\012ALTER TABLE SAMPLE_COMPONENT_MATERIALS ADD CONSTRAINT SCMA_SACO_FK FOREIGN KEY (SACO_ID) REFERENCES SAMPLE_COMPONENTS(ID);\012ALTER TABLE SAMPLE_INPUTS ADD CONSTRAINT SAIN_PROC_FK FOREIGN KEY (PROC_ID) REFERENCES PROCEDURES(ID);\012ALTER TABLE SAMPLE_INPUTS ADD CONSTRAINT SAIN_SAMP_FK FOREIGN KEY (SAMP_ID) REFERENCES SAMPLES(ID);\012\012-- Creating sequences\012\012CREATE SEQUENCE DATA_ID_SEQ;\012CREATE SEQUENCE DATA_TYPE_ID_SEQ;\012CREATE SEQUENCE DATA_VALUE_ID_SEQ;\012CREATE SEQUENCE EXPERIMENT_ID_SEQ;\012CREATE SEQUENCE EXPERIMENT_ATTACHMENT_ID_SEQ;\012CREATE SEQUENCE EXPERIMENT_TYPE_ID_SEQ;\012CREATE SEQUENCE FILE_FORMAT_TYPE_ID_SEQ;\012CREATE SEQUENCE INVALIDATION_ID_SEQ;\012CREATE SEQUENCE LOCATOR_TYPE_ID_SEQ;\012CREATE SEQUENCE MATERIAL_BATCH_ID_SEQ;\012CREATE SEQUENCE MATERIAL_ID_SEQ;\012CREATE SEQUENCE MATERIAL_PROPERTY_ID_SEQ;\012CREATE SEQUENCE MATERIAL_TYPE_ID_SEQ;\012CREATE SEQUENCE MTPT_ID_SEQ;\012CREATE SEQUENCE OBSERVABLE_TYPE_ID_SEQ;\012CREATE SEQUENCE ORGANIZATION_ID_SEQ;\012CREATE SEQUENCE PERSON_ID_SEQ;\012CREATE SEQUENCE PROCEDURE_ID_SEQ;\012CREATE SEQUENCE PROCEDURE_TYPE_ID_SEQ;\012CREATE SEQUENCE PROJECT_ID_SEQ;\012CREATE SEQUENCE PROPERTY_TYPE_ID_SEQ;\012CREATE SEQUENCE SAMPLE_COMPONENT_ID_SEQ;\012CREATE SEQUENCE SAMPLE_ID_SEQ;\012CREATE SEQUENCE SAMPLE_INPUT_ID_SEQ;\012CREATE SEQUENCE SAMPLE_TYPE_ID_SEQ;\012CREATE SEQUENCE SCMA_ID_SEQ;\012\012-- Creating indices\012\012CREATE INDEX DATA_OBTY_FK_I ON DATA (OBTY_ID);\012CREATE INDEX DATA_PROC_FK_I ON DATA (PROC_ID_ACQUIRED_BY);\012CREATE INDEX DATA_SAMP_DERIVED_FROM_FK_I ON DATA (SAMP_ID_DERIVED_FROM);\012CREATE INDEX DATA_SAMP_FK_I ON DATA (SAMP_ID_ACQUIRED_FROM);\012CREATE INDEX DAVA_DATA_FK_I ON DATA_VALUES (DATA_ID);\012CREATE INDEX DAVA_SACO_FK_I ON DATA_VALUES (SACO_ID);\012CREATE INDEX EXDA_FFTY_FK_I ON EXTERNAL_DATA (FFTY_ID);\012CREATE INDEX EXDA_LOTY_FK_I ON EXTERNAL_DATA (LOTY_ID);\012CREATE INDEX EXPE_EXTY_FK_I ON EXPERIMENTS (EXTY_ID);\012CREATE INDEX EXPE_MATE_FK_I ON EXPERIMENTS (MATE_ID_STUDY_OBJECT);\012CREATE INDEX EXPE_PERS_FK_I ON EXPERIMENTS (PERS_ID_REGISTERER);\012CREATE INDEX EXPE_PROJ_FK_I ON EXPERIMENTS (PROJ_ID);\012CREATE INDEX EXAT_EXPE_FK_I ON EXPERIMENT_ATTACHMENTS (EXPE_ID);\012CREATE INDEX EXAT_PERS_FK_I ON EXPERIMENT_ATTACHMENTS (PERS_ID_REGISTERER);\012CREATE INDEX INVA_PERS_FK_I ON INVALIDATIONS (PERS_ID_REGISTERER);\012CREATE INDEX MABA_MATE_FK_I ON MATERIAL_BATCHES (MATE_ID);\012CREATE INDEX MABA_PERS_FK_I ON MATERIAL_BATCHES (PERS_ID_REGISTERER);\012CREATE INDEX MABA_PROC_FK_I ON MATERIAL_BATCHES (PROC_ID);\012CREATE INDEX MAPR_MATE_FK_I ON MATERIAL_PROPERTIES (MATE_ID);\012CREATE INDEX MAPR_MTPT_FK_I ON MATERIAL_PROPERTIES (MTPT_ID);\012CREATE INDEX MAPR_PERS_FK_I ON MATERIAL_PROPERTIES (PERS_ID_REGISTERER);\012CREATE INDEX MATE_MATE_FK_I ON MATERIALS (MATE_ID_INHIBITOR_OF);\012CREATE INDEX MATE_MATY_FK_I ON MATERIALS (MATY_ID);\012CREATE INDEX MATE_PERS_FK_I ON MATERIALS (PERS_ID_REGISTERER);\012CREATE INDEX MTPT_MATY_FK_I ON MATERIAL_TYPE_PROPERTY_TYPES (MATY_ID);\012CREATE INDEX MTPT_PERS_FK_I ON MATERIAL_TYPE_PROPERTY_TYPES (PERS_ID_REGISTERER);\012CREATE INDEX MTPT_PRTY_FK_I ON MATERIAL_TYPE_PROPERTY_TYPES (PRTY_ID);\012CREATE INDEX PROC_EXPE_FK_I ON PROCEDURES (EXPE_ID);\012CREATE INDEX PROC_PCTY_FK_I ON PROCEDURES (PCTY_ID);\012CREATE INDEX PROC_PERS_FK_I ON PROCEDURES (PERS_ID);\012CREATE INDEX PROJ_ORGA_FK_I ON PROJECTS (ORGA_ID);\012CREATE INDEX PRTY_DATY_FK_I ON PROPERTY_TYPES (DATY_ID);\012CREATE INDEX PRTY_PERS_FK_I ON PROPERTY_TYPES (PERS_ID_REGISTERER);\012CREATE INDEX SACO_SAMP_FK_I ON SAMPLE_COMPONENTS (SAMP_ID);\012CREATE INDEX SAIN_PROC_FK_I ON SAMPLE_INPUTS (PROC_ID);\012CREATE INDEX SAIN_SAMP_FK_I ON SAMPLE_INPUTS (SAMP_ID);\012CREATE INDEX SAMP_INVA_FK_I ON SAMPLES (INVA_ID);\012CREATE INDEX SAMP_PERS_FK_I ON SAMPLES (PERS_ID_REGISTERER);\012CREATE INDEX SAMP_SAMP_FK_I_GENERATED_FROM ON SAMPLES (SAMP_ID_GENERATED_FROM);\012CREATE INDEX SAMP_SAMP_FK_I_TOP ON SAMPLES (SAMP_ID_TOP);\012CREATE INDEX SAMP_SATY_FK_I ON SAMPLES (SATY_ID);\012CREATE INDEX SCMA_MABA_FK_I ON SAMPLE_COMPONENT_MATERIALS (MABA_ID);\012CREATE INDEX SCMA_SACO_FK_I ON SAMPLE_COMPONENT_MATERIALS (SACO_ID);\012\012-- Miscellaneous\012\012ALTER TABLE DATA ADD CONSTRAINT DATA_SAMP_ARC_CK CHECK ((SAMP_ID_ACQUIRED_FROM IS NOT NULL AND SAMP_ID_DERIVED_FROM IS NULL) OR (SAMP_ID_ACQUIRED_FROM IS NULL AND SAMP_ID_DERIVED_FROM IS NOT NULL));\012