Answered step by step
Verified Expert Solution
Question
1 Approved Answer
i have these tabels in database sql CREATE TABLE AIRPORT ( Code CHAR(3) NOT NULL, City VARCHAR(30), Name VARCHAR(50), State VARCHAR(50), PRIMARY KEY (Code) );
i have these tabels in database sql
CREATE TABLE AIRPORT (
Code CHAR(3) NOT NULL,
City VARCHAR(30),
Name VARCHAR(50),
State VARCHAR(50),
PRIMARY KEY (Code)
);
CREATE TABLE AIRPLANE_TYPE (
Type_name VARCHAR(50) NOT NULL,
Max_seats INT NOT NULL CHECK(Max_seats > 0),
Company VARCHAR(50),
PRIMARY KEY (Type_name)
);
CREATE TABLE AIRPLANE (
Id VARCHAR(4) NOT NULL,
No_seats INT NOT NULL CHECK(No_seats > 0),
Airplane_type VARCHAR(50),
PRIMARY KEY (Id),
FOREIGN KEY (Airplane_type) REFERENCES AIRPLANE_TYPE(Type_name)
);
CREATE TABLE CAN_LAND (
Airport_code CHAR(3) NOT NULL,
Airplane_type_name VARCHAR(50) NOT NULL,
PRIMARY KEY (Airport_code, Airplane_type_name),
FOREIGN KEY (Airport_code) REFERENCES AIRPORT(Code) ,
FOREIGN KEY (Airplane_type_name) REFERENCES AIRPLANE_TYPE(Type_name)
);
CREATE TABLE FLIGHT (
num VARCHAR(20) NOT NULL,
Airline VARCHAR(20),
Weekdays INT,
PRIMARY KEY (num)
);
CREATE TABLE FLIGHTLEG (
Leg_number INT UNIQUE NOT NULL,
Flight_number VARCHAR(20) UNIQUE NOT NULL,
Depart_airport_code CHAR(3),
scheduled_depart_time TIMESTAMP,
Arrive_airport_code CHAR(3),
scheduled_arrive_time TIMESTAMP,
PRIMARY KEY( Leg_number ,Flight_number),
FOREIGN KEY(Depart_airport_code) REFERENCES AIRPORT(Code),
FOREIGN KEY(Arrive_airport_code) REFERENCES AIRPORT(Code)
);
CREATE TABLE FARE(
Code_no INT NOT NULL,
Flight_number VARCHAR(20) UNIQUE NOT NULL,
Amount FLOAT,
Restrictions VARCHAR(70),
PRIMARY KEY(Code_no, Flight_number),
FOREIGN KEY(Flight_number) REFERENCES FLIGHT(num)
);
CREATE TABLE LEG_INSTANCE(
Name VARCHAR(30) UNIQUE NOT NULL,
Leg_number INT UNIQUE NOT NULL,
Flight_number VARCHAR(20) UNIQUE NOT NULL,
Airplane_id VARCHAR(4) NOT NULL,
Leg_date DATE NOT NULL,
Depart_airport_code CHAR(3),
Depart_time TIMESTAMP,
Arrive_airport_code CHAR(3),
Arrival_time TIMESTAMP,
PRIMARY KEY(Name, Leg_number ,Flight_number, Airplane_id),
FOREIGN KEY(Leg_number) REFERENCES FLIGHTLEG(Leg_number),
FOREIGN KEY(Flight_number) REFERENCES FARE(Flight_number),
FOREIGN KEY(Airplane_id) REFERENCES AIRPLANE(Id),
FOREIGN KEY(Depart_airport_code) REFERENCES AIRPORT(Code),
FOREIGN KEY(Arrive_airport_code) REFERENCES AIRPORT(Code)
);
CREATE TABLE SEAT(
Seat_no VARCHAR(5) NOT NULL,
Leg_instance_name VARCHAR(30) NOT NULL,
Leg_number INT NOT NULL,
Flight_number VARCHAR(20) NOT NULL,
Customer_phone VARCHAR(10) NOT NULL,
Customer_name VARCHAR(30) NOT NULL,
PRIMARY KEY(Seat_no, Leg_instance_name, Leg_number, Flight_number),
FOREIGN KEY(Leg_instance_name) REFERENCES LEG_INSTANCE(Name),
FOREIGN KEY(Leg_number) REFERENCES LEG_INSTANCE(Leg_number),
FOREIGN KEY(Flight_number) REFERENCES LEG_INSTANCE(Flight_number)
);
----------------------------------------------
you need to write command for these :
Views list:
1. Available Airplanes: This view returns the airplane type name, max seats, manufacture company and number of available airplanes from that type.
2.Flight legs : This view returns all flight legs, working weekdays and airlines based on their flight number.
Queries list :
1. List name and phone number for each customer whose flight date is 1-1-2023.
2. List flight fare for each flight with at least two legs.
3. List all airplanes id from Boeing company.
4. Find the most visited airport.
5. Find the highest flight fare and the number of its legs.
6. List all morning flights legs.
7. List all airplane types that can land in Riyadh.
8. List all the delayed legs.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started