Sunteți pe pagina 1din 5

Below are the DDL statement to create the table as given in the ERD.

All the tables with given


attributes are included in this. CREATE TABLE statement is used to create the table. Primary key
and Foreign key constraint are clearly mentioned in table where necessary.

DDL Statement
-- Creating table Airport

CREATE TABLE IF NOT EXISTS Airport

Ap_Code INT,

Ap_Name VARCHAR(50),

Ap_City VARCHAR(25),

Ap_State VARCHAR(5),

Ap_Country VARCHAR(25),

PRIMARY KEY (Ap_Code)

);

-- Creating table Pilot

CREATE TABLE IF NOT EXISTS Pilot

Pi_CAA_licenseNum INT,

Pi_FirstName VARCHAR(25),

Pi_Initial VARCHAR(10),

Pi_LastName VARCHAR(25),

Pi_DOB DATE,

Pi_StreetAddress VARCHAR(50),

Pi_Subrub VARCHAR(25),

Pi_City VARCHAR(25),

Pi_StateOfProvince VARCHAR(25),

Pi_PostalCodeOrZip VARCHAR(10),

Pi_Country VARCHAR(25),
Pi_RegularPhone VARCHAR(10),

Pi_EmergencyPhone VARCHAR(10),

Pi_Email VARCHAR(25),

Pi_Salary FLOAT,

PRIMARY KEY (Pi_CAA_licenseNum)

);

-- Creating table Passenger

CREATE TABLE IF NOT EXIST Passenger

Pass_ID INT,

Pass_Title VARCHAR(10),

Pass_FirstName VARCHAR(25),

Pass_LastName VARCHAR(25),

Pass_DOB DATE,

Pass_StreetAddress VARCHAR(50),

Pass_Subrub VARCHAR(20),

Pass_City VARCHAR(25),

Pass_StateOfProvince VARCHAR(25),

Pass_PostalCodeOrZip VARCHAR(10),

Pass_Country VARCHAR(25),

Pass_Email VARCHAR(25),

Pass_PhCountryCode VARCHAR(5),

Pass_PhAreaCode VARCHAR(5),

Pass_PhNum VARCHAR(11),

PRIMARY KEY (Pass_ID)

);

-- Creating table Aircraft Type


CREATE TABLE IF NOT EXIST Aircraft_Type

AT_ID INT,

AT_Name VARCHAR(25),

PRIMARY KEY (AT_ID)

);

-- Creating table Aircraft Manufacturer

CREATE TABLE IF NOT EXIST Aircraft_Manufacturer

AM_ID INT,

AM_Name VARCHAR(25),

PRIMARY KEY (AM_ID)

);

-- Creating table Booking Class

CREATE TABLE IF NOT EXIST Booking_Class

BC_ID INT,

BC_FliCostFactor VARCHAR(25),

BC_Description VARCHAR(25),

PRIMARY KEY (BC_ID)

);

-- Creating table Aircraft

CREATE TABLE IF NOT EXIST Aircraft

Ac_SerialNum INT,

Ac_ModelNum VARCHAR(25),

Ac_NumSeats INT,
Ac_ManufacturerDate DATE,

AT_ID INT,

AM_ID INT,

PRIMARY KEY (Ac_SerialNum),

FOREIGN KEY (AT_ID) REFERENCES Aircraft_Type (AT_ID),

FOREIGN KEY (AM_ID) REFERENCES Aircraft_Manufacturer (AM_ID)

);

-- Creating table AircraftType Airport

CREATE TABLE IF NOT EXIST AircraftType_Airport

AT_ID INT,

Ap_Code INT,

PRIMARY KEY (AT_ID, Ap_Code),

FOREIGN KEY (AT_ID) REFERENCES Aircraft_Type (AT_ID),

FOREIGN KEY (Ap_Code) REFERENCES Airport (Ap_Code)

);

-- Creating table Flight

CREATE TABLE IF NOT EXIST Flight

Fli_Num INT,

Fli_Fare FLOAT,

Fli_NumAvailSeats INT,

Fli_DeptDate DATE,

Fli_DepTime TIME,

Fli_ArrDate DATE,

Fli_ArrTime TIME,

Ac_SerialNum INT,
Pi_CAA_LicenseNum INT,

Ap_Code INT,

PRIMARY KEY (Fli_Num),

FOREIGN KEY (Ac_SerialNum) REFERENCES Aircraft (Ac_SerialNum),

FOREIGN KEY (Pi_CAA_LicenseNum) REFERENCES Pilot (Pi_CAA_LicenseNum),

FOREIGN KEY (Ap_Code) REFERENCES Airport (Ap_Code)

);

-- Creating table Booking

CREATE TABLE Booking

Bk_ID INT,

Bk_SeatNum INT,

Bk_Date DATE,

Bk_Time TIME,

Bk_CreditCard VARCHAR(25),

Bk_TotalCost FLOAT,

Bk_PaymentStatus VARCHAR(10),

BC_ID INT,

Pass_ID INT,

Fli_Num INT,

PRIMARY KEY (Bk_ID),

FOREIGN KEY (BC_ID) REFERENCES Booking_Class (BC_ID),

FOREIGN KEY (Pass_ID) REFERENCES Passenger (Pass_ID),

FOREIGN KEY (Fli_Num) REFERENCES Flight (Fli_Num)

);