2019-08-27 03:20:34 +00:00
|
|
|
-- Part 1; add drops so that we can keep re-running this file.
|
|
|
|
DROP TABLE Reservation;
|
|
|
|
DROP TABLE TravelAgent;
|
|
|
|
DROP TABLE Cruise;
|
|
|
|
DROP TABLE Company;
|
|
|
|
DROP TABLE Customer;
|
|
|
|
DROP SEQUENCE customerID_seq;
|
|
|
|
DROP SEQUENCE cruiseID_seq;
|
|
|
|
DROP SEQUENCE travelAgentID_seq;
|
|
|
|
DROP SEQUENCE reservationID_seq;
|
|
|
|
|
|
|
|
-- Part 2; Set up schema and insert data.
|
|
|
|
|
2019-08-27 02:06:41 +00:00
|
|
|
CREATE TABLE Customer(
|
|
|
|
customerID NUMBER,
|
|
|
|
firstName VARCHAR2(15),
|
|
|
|
lastName VARCHAR2(15),
|
|
|
|
address VARCHAR2(30),
|
2019-08-27 02:45:32 +00:00
|
|
|
phone NUMBER(10),
|
2019-08-27 04:11:48 +00:00
|
|
|
age NUMBER(3),
|
2019-08-27 02:54:49 +00:00
|
|
|
CONSTRAINT Customer_pk PRIMARY KEY(customerID),
|
|
|
|
CONSTRAINT Customer_U1 UNIQUE(firstName, lastName, phone),
|
2019-08-27 03:14:59 +00:00
|
|
|
CONSTRAINT Customer_phoneNumber_val CHECK (phone IS NOT NULL)
|
2019-08-27 02:06:41 +00:00
|
|
|
);
|
2019-08-27 02:27:33 +00:00
|
|
|
CREATE SEQUENCE customerID_seq;
|
2019-08-27 02:06:41 +00:00
|
|
|
|
2019-08-27 03:12:59 +00:00
|
|
|
CREATE TABLE Company(
|
|
|
|
companyName VARCHAR2(15),
|
|
|
|
stockSymbol CHAR(4),
|
|
|
|
website VARCHAR2(40),
|
|
|
|
CONSTRAINT Company_pk PRIMARY KEY(companyName),
|
|
|
|
CONSTRAINT Company_stockSymbol_U UNIQUE(stockSymbol)
|
|
|
|
);
|
|
|
|
|
2019-08-27 02:06:41 +00:00
|
|
|
CREATE TABLE Cruise(
|
|
|
|
cruiseID NUMBER,
|
|
|
|
cruiseName VARCHAR2(25),
|
|
|
|
departurePort VARCHAR2(20),
|
|
|
|
days NUMBER(2),
|
|
|
|
companyName VARCHAR2(15),
|
|
|
|
shipName VARCHAR2(30),
|
2019-08-27 02:45:32 +00:00
|
|
|
price NUMBER(7, 2),
|
2019-08-27 03:12:59 +00:00
|
|
|
CONSTRAINT Cruise_pk PRIMARY KEY(cruiseID),
|
2019-08-27 03:18:03 +00:00
|
|
|
CONSTRAINT Cruise_companyName_fk FOREIGN KEY (companyName) REFERENCES Company(companyName) ON DELETE SET NULL
|
2019-08-27 02:06:41 +00:00
|
|
|
);
|
2019-08-27 02:27:33 +00:00
|
|
|
CREATE SEQUENCE cruiseID_seq;
|
2019-08-27 02:06:41 +00:00
|
|
|
|
|
|
|
CREATE TABLE TravelAgent(
|
|
|
|
travelAgentID NUMBER,
|
|
|
|
firstName VARCHAR2(15),
|
|
|
|
lastName VARCHAR2(20),
|
|
|
|
title VARCHAR2(15),
|
2019-08-27 02:45:32 +00:00
|
|
|
salary NUMBER(7, 2),
|
2019-08-27 03:14:59 +00:00
|
|
|
CONSTRAINT TravelAgent_pk PRIMARY KEY(travelAgentID),
|
|
|
|
CONSTRAINT TravelAgent_title_val CHECK (title IN ('Assistant', 'Agent', 'Manager'))
|
2019-08-27 02:06:41 +00:00
|
|
|
);
|
2019-08-27 02:27:33 +00:00
|
|
|
CREATE SEQUENCE travelAgentID_seq;
|
2019-08-27 02:06:41 +00:00
|
|
|
|
2019-08-27 03:12:59 +00:00
|
|
|
CREATE TABLE Reservation(
|
|
|
|
reservationID NUMBER,
|
|
|
|
customerID NUMBER,
|
|
|
|
cruiseID NUMBER,
|
|
|
|
travelAgentID NUMBER,
|
|
|
|
travelDate DATE,
|
|
|
|
CONSTRAINT Reservation_pk PRIMARY KEY(reservationID),
|
2019-08-27 03:15:59 +00:00
|
|
|
CONSTRAINT Reservation_customerID_fk FOREIGN KEY (customerID) REFERENCES Customer(customerID) ON DELETE CASCADE,
|
|
|
|
CONSTRAINT Reservation_cruiseID_fk FOREIGN KEY (cruiseID) REFERENCES Cruise(cruiseID) ON DELETE CASCADE,
|
|
|
|
CONSTRAINT Reservation_travelAgentID_fk FOREIGN KEY (travelAgentID) REFERENCES TravelAgent(travelAgentID) ON DELETE CASCADE
|
2019-08-27 03:12:59 +00:00
|
|
|
);
|
|
|
|
CREATE SEQUENCE reservationID_seq;
|