Create table airport airportcode char3 not null name

Info icon This preview shows pages 2–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CREATE TABLE AIRPORT ( AIRPORT_CODE CHAR(3) NOT NULL, NAME VARCHAR(30) NOT NULL, CITY VARCHAR(30) NOT NULL, STATE VARCHAR(30), PRIMARY KEY (AIRPORT_CODE) ); CREATE TABLE FLIGHT ( NUMBER VARCHAR(6) NOT NULL, AIRLINE VARCHAR(20) NOT NULL, WEEKDAYS VARCHAR(10) NOT NULL, PRIMARY KEY (NUMBER) ); CREATE TABLE FLIGHT_LEG ( FLIGHT_NUMBER VARCHAR(6) NOT NULL, LEG_NUMBER INTEGER NOT NULL, DEPARTURE_AIRPORT_CODE CHAR(3) NOT NULL, SCHEDULED_DEPARTURE_TIME TIMESTAMP WITH TIME ZONE, ARRIVAL_AIRPORT_CODE CHAR(3) NOT NULL, SCHEDULED_ARRIVAL_TIME TIMESTAMP WITH TIME ZONE, PRIMARY KEY (FLIGHT_NUMBER, LEG_NUMBER), FOREIGN KEY (FLIGHT_NUMBER) REFERENCES FLIGHT (NUMBER), FOREIGN KEY (DEPARTURE_AIRPORT_CODE) REFERENCES AIRPORT (AIRPORT_CODE), FOREIGN KEY (ARRIVAL_AIRPORT_CODE) REFERENCES AIRPORT (AIRPORT_CODE) ); CREATE TABLE LEG_INSTANCE ( FLIGHT_NUMBER VARCHAR(6) NOT NULL, LEG_NUMBER INTEGER NOT NULL, LEG_DATE DATE NOT NULL, NO_OF_AVAILABLE_SEATS INTEGER, AIRPLANE_ID INTEGER, DEPARTURE_AIRPORT_CODE CHAR(3), DEPARTURE_TIME TIMESTAMP WITH TIME ZONE, ARRIVAL_AIRPORT_CODE CHAR(3), ARRIVAL_TIME TIMESTAMP WITH TIME ZONE, PRIMARY KEY (FLIGHT_NUMBER, LEG_NUMBER, LEG_DATE), FOREIGN KEY (FLIGHT_NUMBER, LEG_NUMBER) REFERENCES FLIGHT_LEG (FLIGHT_NUMBER, LEG_NUMBER), FOREIGN KEY (AIRPLANE_ID) REFERENCES AIRPLANE (AIRPLANE_ID), FOREIGN KEY (DEPARTURE_AIRPORT_CODE) REFERENCES AIRPORT (AIRPORT_CODE), FOREIGN KEY (ARRIVAL_AIRPORT_CODE) REFERENCES AIRPORT (AIRPORT_CODE) ); CREATE TABLE FARES ( FLIGHT_NUMBER VARCHAR(6) NOT NULL, FARE_CODE VARCHAR(10) NOT NULL, AMOUNT DECIMAL(8,2) NOT NULL, RESTRICTIONS VARCHAR(200), PRIMARY KEY (FLIGHT_NUMBER, FARE_CODE), FOREIGN KEY (FLIGHT_NUMBER) REFERENCES FLIGHT (NUMBER) ); CREATE TABLE AIRPLANE_TYPE ( TYPE_NAME VARCHAR(20) NOT NULL, MAX_SEATS INTEGER NOT NULL,
Image of page 2

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
COMPANY VARCHAR(15) NOT NULL, PRIMARY KEY (TYPE_NAME) ); CREATE TABLE CAN_LAND ( AIRPLANE_TYPE_NAME VARCHAR(20) NOT NULL, AIRPORT_CODE CHAR(3) NOT NULL, PRIMARY KEY (AIRPLANE_TYPE_NAME, AIRPORT_CODE), FOREIGN KEY (AIRPLANE_TYPE_NAME) REFERENCES AIRPLANE_TYPE (TYPE_NAME), FOREIGN KEY (AIRPORT_CODE) REFERENCES AIRPORT (AIRPORT_CODE) ); CREATE TABLE AIRPLANE ( AIRPLANE_ID INTEGER NOT NULL, TOTAL_NUMBER_OF_SEATS INTEGER NOT NULL, AIRPLANE_TYPE VARCHAR(20) NOT NULL, PRIMARY KEY (AIRPLANE_ID), FOREIGN KEY (AIRPLANE_TYPE) REFERENCES AIRPLANE_TYPE (TYPE_NAME) ); CREATE TABLE SEAT_RESERVATION ( FLIGHT_NUMBER VARCHAR(6) NOT NULL, LEG_NUMBER INTEGER NOT NULL, LEG_DATE DATE NOT NULL, SEAT_NUMBER VARCHAR(4), CUSTOMER_NAME VARCHAR(30) NOT NULL, CUSTOMER_PHONE CHAR(12), PRIMARY KEY (FLIGHT_NUMBER, LEG_NUMBER, LEG_DATE, SEAT_NUMBER), FOREIGN KEY (FLIGHT_NUMBER, LEG_NUMBER, LEG_DATE) REFERENCES LEG_INSTANCE (FLIGHT_NUMBER, LEG_NUMBER, LEG_DATE) ); 8.9 Consider the LIBRARY relational database schema of Figure 6.12. Choose the appropriate action (reject, cascade, set to null, set to default) for each referential integrity constraint, both for DELETE of a referenced tuple, and for UPDATE of a primary key attribute value in a referenced tuple. Justify your choices.
Image of page 3
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern