5. SQL Script

Excerpt from schema_inheritance.sql

                
...

CREATE TABLE PERSON_TYPE (
    ID integer identity primary key,  
    NAME varchar(50) not null,
    CREATED timestamp,
    CONSTRAINT IDX_PERSON_TYPE_ID PRIMARY KEY (ID)
);

CREATE TABLE PERSON (
    ID integer identity primary key,  
    FIRST_NAME varchar(50) not null,
    LAST_NAME varchar(50) not null,
    TYPE integer, 
    CREATED timestamp,
    CONSTRAINT IDX_PERSON_ID PRIMARY KEY (ID),
    CONSTRAINT FK_PERSON_TYPE FOREIGN KEY (TYPE) REFERENCES PERSON_TYPE(ID)
);

CREATE TABLE PERSON_STUDENT (
    ID integer not null,  
    SCHOOL_NAME varchar(50) not null,
    CREATED timestamp,
    CONSTRAINT FK_PERSON_STUDENT_ID FOREIGN KEY (ID) REFERENCES PERSON(ID) on delete cascade
);

CREATE TABLE PERSON_PROFESSIONAL (
    ID integer not null,  
    COMPANY_NAME varchar(50) not null,
    CREATED timestamp,
    CONSTRAINT FK_PERSON_PROFESSIONAL_ID FOREIGN KEY (ID) REFERENCES PERSON(ID) on delete cascade
);

CREATE TABLE ADDRESS (
    ID integer identity primary key,
    PERSON_ID integer,  
    ADDRESS varchar(255),
    CITY varchar(50) not null,
    STATE varchar(50) null,
    ZIP_POSTAL varchar(30) not null,
    COUNTRY varchar(50) not null,
    CREATED timestamp,
    CONSTRAINT IDX_ADDRESS_ID PRIMARY KEY (ID),
    CONSTRAINT FK_ADDRESS_PERSON_ID FOREIGN KEY (PERSON_ID) REFERENCES PERSON(ID) on delete cascade
);

...