Вы находитесь на странице: 1из 28

CS 352 Database Management Systems

Design Report

Airline Company Data Management System

Group 40

Ozan Karsavuran

Ahmet Rıdvan Duran

İhsan Mert Özçelik

4/27/2011

http://code.google.com/p/rom-airlines

Tables of contents

1-

Table schemas, FD and Normalization of Tables

 

2

2-

Use Case Diagram

9

3-

User interface design and corresponding SQL statements

10

4-

Advanced Database Components

 

23

5-

Implementation Plan

 

26

6-

ER Diagram for Database

 

27

Table schemas, FD and Normalization of Tables

We did not write trivial functional dependencies. Our flight table was not satisfy 3NF because of distance between departure city and land city, to overcome that we create new table named Distance that store distance between two airports. After that all of our tables satisfy 3NF.

SystemUser( id int(11) not null email varchar(30) not null name varchar(30) not null birthday datetime not null password varchar(64) not null phoneNumber int not null primary key (id)

)

Functional Dependencies:

email --> email, name, birthday, password, phoneNumber

id --> email, name, birthday, password, phoneNumber Candidate Key: id

Staff(

id int(11) not null salary int(11) not null TcIdNo int(11) not null job varchar(30) not null primary key(id) foreign key(id) references SystemUser(id)

)

Functional Dependencies:

id --> email, salary, TcIdNo email --> email, salary, TcIdNo TcIdNo --> email, salary, TcIdNo Candidate Key: id

SystemAdmin( id int(11) not null primary key(id) foreign key(id) references Staff(id)

)

no functional dependency. Candidate Key: id

SalesOfficer ( id int(11) not null primary key(id) foreign key(id) references Staff(id)

)

no functional dependency Candidate Key: id

CabinAttendant( id int(11) not null primary key(id) foreign key(id) references Staff(id)

)

no functional dependency

Candidate Key: id

Pilot(

id int(11) not null primary key(id) foreign key(id) references Staff(id)

)

no functional dependency Candidate Key: id

PilotHasLicence( pilotId int(11) not null licenceId int(11) not null primary key(pilotId, licenceId) foreign key(pilotId) references Pilot(id) foreign key(licenceId) references Licence(id)

)

no functional dependency Candidate Key: pilotId,licenceId

Licence(

id int(11) not null name varchar(20) not null primary key(int)

)

Functional Dependencies id --> id, name Candidate Key: id

LicenceForPlane( licenceId int(11) not null planeModelId int(11) not null primary key(licenceId,planeModelId) foreign key(licenceId) references Licence(Id) foreign key(planeModelId) references PlaneModel(Id)

)

no functional dependency Candidate Key: (licenceId,planeModelId)

Distance( departureAirport int(11) not null landingAirport int(11) not null distance int(11) not null primaryKey(departureAirport,landingAirport) foreignKey(departureAirport) references Airport(id) foreignKey(landingAirport) references Airport(id)

)

Functional Dependencies departureAirport , landingAirport → distance Candidate Key: (departureAirport , landingAirport)

CheckInOfficer( id int(11) not null AirportId int(11) primary key(id) foreign key(id) references Staff(id) foreign key(AirportId) references Airport(id)

)

-There is no FD -Candidate Key(s): id

Customer( id int(11) not null primary key(id) foreign key(id) references SystemUser(id)

)

-There is no FD -Candidate Key(s): id

Reservation( id int (11) not null paymentStatus bool not null customerId int(11) primary key(id) foreign key(customerId) references Customer(id)

)

-FD: id  paymentStatus, id, customerId -Candidate Key(s): id

Passenger( id int (11) not null name var char(30) not null birthday datetime primary key(id)

)

-FD: id name,birthday, datetime

-Candidate Key(s): id

Seat(

passengerId int(11) not null flightId int (11) not null flightDate datetime not null seatNo int(4) not null primary key(passengerId, flightId, flightDate) foreign key (passengerId) references Passenger(id) foreign key (flightId) references Flight(Id) foreign key (flightDate) references Flight(Date)

)

-FD: passengerId, flightId, flightDate seatNo flightId,flightDate,seatNo passengerId -Candidate Key(s): passengerId, flightId, flightDate

Flight(

id int(11) not null date datetime not null planeId int(11) not null departureAirport-int(11) not null departureTime datetime not null landingAirport-int(11)-not null landingTime datetime not null RemainingBussSeats int(4) RemainingFirstSeats int(4) RemainingEconSeats int(4) primary key(id , date) foreign key(planeId) references Plane(id) foreign key(departureAirport) references Airport(id) foreign key(landingAirport) references Airport(id)

)

-FD: id,datedistance, planeId, departureAirport, departureAirport,landingAirport, landingTime

date, departureAirport,departureTime,landingAirport id

-Candidate Key(s):

id,date date, departureAirport,departureTime,landingAirport

ReservationFlight( flightId int(11) not null flightDate datetime not null reserveId int(11) not null primary key(flightId, flightDate, reserveId) foreign key(flightId,flightdate) references Flight(id,date) foreign key(reserveId)-references-Reservation(id)

)

No functional dependencies. Candidate Key: flightId, flightDate, reserveId

ReservationPassenger( reservationId int(11) not null passengerId int(11) not null primary key(reservationId,passengerId) foreign key(reservationId) references Reservation(id) foreign key(passengerId) references Passenger(id)

)

No functional dependencies. Candidate Key: reservationId, passengerId

Assigned ( cabinAttendantId int(11) not null flightId int(11) not null flightDate datetime not null primary key(flightId, flightDate cabinAttendantId) foreignKey(cabinAttendantId) references CabinAttendant(id) foreignKey(flightId, flightDate) references Flight(id,date)

)

No functional dependencies. Candidate Key: flightId, flightDate, cabinAttendantId

Plane(

id int(11) not null name varchar(20) not null modelId int(11) not null primary key(id) foreign key(modelId) references PlaneModel(id)

)

Functional Dependencies:

id id, name, modelId Candidate Key: id

PlaneModel( id int(11) not null name varchar(20) nut null bussCapacity int(4) not null firstCapacity int(4) not null econCapacity int(4) not null primary key(id)

)

Functional Dependencies:

id id, name, bussCapacity, firstCapacity, econCapacity Candidate Key: id

Airport(

id int(11) not null cityId int(11) not null primary key(id) foreign key(cityId) references City(id)

)

Functional Dependencies:

id id, cityId

Candidate Key: id

City(

id int (11) not null name var char (20) country var char(20) primary key(id)

)

Functional Dependencies:

id id,city Candidate Key: id

Flies(

name, country

pilotId int(11) not null flightId int(11) not null flightDate datetime not null primary key(pilotId, flightId, flightDate) foreign key(pilotId) references Pilot(id) foreignKey(flightId, flightDate) references Flight(id,date)

)

No functional dependencies. Candidate Key: pilotId, flightId, flightDate

Country ( id int(11) not null name var char(20) not null primary key (id)

)

No functional dependencies.

Candidate Key: id

Use Case Diagram

Use Case Diagram 9

User interface design and corresponding SQL statements:

Log in the system

design and corresponding SQL statements: Log in the system SELECT S.id, S.password FROM SystemUser S WHERE

SELECT S.id, S.password

FROM SystemUser S

WHERE email = $email

Create a new customer account

S WHERE email = $email Create a new customer account INSERT INTO SystemUser VALUES ($id,$email,$name,

INSERT

INTO SystemUser VALUES ($id,$email,$name, $birthday,$password, $phoneNumber )

INSERT INTO Customer VALUES ($id)

Add a staff account

Add a staff account INSERT INTO SystemUser VALUES ($id,$email,$name, $birthday,$password, $phoneNumber ) INSERT INTO Staff

INSERT INTO SystemUser VALUES ($id,$email,$name, $birthday,$password, $phoneNumber )

INSERT INTO Staff

VALUES ($id,$email, $job,$salary, $TcIdNo)

If Staff is System Admin

INSERT INTO SystemAdmin

VALUES ($id)

If Staff is Sales Officer

INSERT INTO SalesOfficer

VALUES ($id)

If Staff is Cabin Attendant

INSERT INTO CabinAttendant

VALUES ($id)

If Staff is Pilot

INSERT INTO Pilot VALUES ($id)

If Staff is Check-in Officer

INSERT INTO CheckInOfficer VALUES ($id, $ AirportId)

Edit staff

UPDATE SystemUser SET email=$email, name=$name, birthday=$birthday, password = $password, phoneNumber=$ phoneNumber WHERE id=$id

UPDATE Staff SET email = $email, salary = $salary, TcIdNo = $TcIdNo WHERE id=$id

If Staff is Check-in Officer

UPDATE CheckInOfficer SET AirportId = $AirportId WHERE id=$id

View Staff

SET AirportId = $AirportId WHERE id=$id View Staff SELECT * FROM SystemUser SU,Staff ST WHERE SU.id=ST.id

SELECT *

FROM SystemUser SU,Staff ST

WHERE SU.id=ST.id AND (SU.TcIdNo=$input OR SU.name=$input OR Su.email=$input)

View Customer

SELECT * FROM SystemUser sU, Customer C WHERE C.id=Su.id AND(sU.name = $input OR sU.id=$input OR sU.email=$input)

Assign Cabin Attendant

Assign Cabin Attendant INSERT INTO Assigned VALUES ($staffId,$flighId,$date) Edit Licences of Pilot INSERT INTO

INSERT INTO Assigned VALUES ($staffId,$flighId,$date) Edit Licences of Pilot

VALUES ($staffId,$flighId,$date) Edit Licences of Pilot INSERT INTO PilotHasLicence VALUES ($pilotId,$licenceId)

INSERT INTO PilotHasLicence VALUES ($pilotId,$licenceId) DELETE FROM PilotHasLicence WHERE pilotId = $pilotId AND licenseId =

$licenceId)

Manage Licences

Manage Licences DELETE FROM Licence WHERE id = $id Edit Licence INSERT INTO LicenceForPlane(licenceId,planeModelId) VALUES

DELETE FROM Licence WHERE id = $id

Edit Licence

INSERT INTO LicenceForPlane(licenceId,planeModelId)

VALUES ($licenceID, $model)

DELETE FROM LicenceForPlane WHERE licenceId = $licence AND planeModelId = $ model

Add Licence

INSERT INTO Licence(id,name) VALUES ($name)

Assign Pilot

INSERT INTO Licence(id,name) VALUES ($name) Assign Pilot INSERT INTO Flies (pilotId, flightId, flightDate)

INSERT INTO Flies (pilotId, flightId, flightDate) VALUES($pilot,$flight,$date)

Assign Check-in Officer

Assign Check-in Officer UPDATE CheckInOfficer SET AirportId = $id WHERE id=$id Add / Edit City Add:

UPDATE CheckInOfficer SET AirportId = $id WHERE id=$id Add / Edit City

SET AirportId = $id WHERE id=$id Add / Edit City Add: INSERT INTO City (id, name,

Add:

INSERT INTO City (id, name, country) VALUES ($id,$name,$country)

Edit:

UPDATE City (id, name, country) SET id =$id, name=$name, country=$country WHERE id=$id

If country is “other”, the new country is inserted into country table.

INSERT INTO Country(name, id) VALUES ($name, $id)

Manage Airport

INTO Country(name, id) VALUES ($name, $id) Manage Airport View: SELECT * FROM Airport A, City C,

View:

SELECT * FROM Airport A, City C, Country Ct WHERE A.cityId = C.cityId AND C.countryId = Ct.id

Add:

INSERT INTO Airport (id, name, cityId) VALUES ($id, $name, $cityId)

Delete:

DELETE FROM Airport (id, name, cityId) WHERE id = $id

Edit:

UPDATE Airport (id, name, cityId) SET id =$id, name=$name, cityId = $cityId WHERE id=$id

Manage Plane Model

Manage Plane Model View: SELECT * FROM PlaneModel(id, name, bussCapacity, firstCapacity, econCapacity) Add: INSERT INTO

View:

SELECT * FROM PlaneModel(id, name, bussCapacity, firstCapacity, econCapacity)

Add:

INSERT INTO PlaneModel(id, name, bussCapacity, firstCapacity, econCapacity) VALUES ($id, $name, $bussCapacity, $firstCapacity, $econCapacity)

Delete:

DELETE FROM PlaneModel(id, name, bussCapacity, firstCapacity, econCapacity) WHERE id = $id

Edit:

UPDATE PlaneModel(id, name, bussCapacity, firstCapacity, econCapacity) SET id =$id, name=$name, bussCapacity = $bussCapacity, firstCapacity = $firstCapacity, econCapacity = $econCapacity WHERE id=$id

Manage Plane

bussCapacity = $bussCapacity, firstCapacity = $firstCapacity, econCapacity = $econCapacity WHERE id=$id Manage Plane 17

View:

SELECT * FROM Plane P(id,name, modelId), PlaneModel PM (id, name, bussCapacity, firstCapacity, econCapacity) WHERE P.modelId = PM.id

Add:

INSERT INTO Plane(id,name, modelId) VALUES ($id,$name, $modelId)

Delete:

DELETE FROM Plane(id,name, modelId) WHERE id = $id

Manage Flight

FROM Plane(id,name, modelId) WHERE id = $id Manage Flight View Airports: SELECT C.name, A.name FROM Airport

View Airports:

SELECT C.name, A.name

FROM Airport A, City C

WHERE A.id = C.id

View Planes:

SELECT *

FROM Plane

Add Flight:

INSERT INTO Flight VALUES ($id, $date, $plane, $departure, $depTime, $land, $landTime)

Edit Flight:

UPDATE Flight

SET id = $id, date = $date, planeId = $plane, departureAirport = $departure, departureTime = $depTime, landingAirport = $land, landingTime = $landTime

WHERE id = $id

Delete flight:

DELETE FROM Flight WHERE id = $id

View Flights:

SELECT *

FROM Flight

WHERE id = $id, date = $date, planeId = $plane, departureAirport = $departure, departureTime = $depTime, landingAirport = $land, landingTime = $landTime

Make Reservation

= $land, landingTime = $landTime Make Reservation Schedule Flights SELECT * FROM Flight WHERE date =

Schedule Flights

SELECT * FROM Flight WHERE date = $date AND landingAirport = $From AND departureAirport = $To

Add Passenger INSERT INTO Passenger VALUES($id,$name,$birthday) 20

Add Passenger

Add Passenger INSERT INTO Passenger VALUES($id,$name,$birthday) 20

INSERT INTO Passenger VALUES($id,$name,$birthday)

Create Reservation INSERT INTO Reservation VALUES ($id, $payment, $e-mail) Online Check-In SELECT RF.flightId,
Create Reservation INSERT INTO Reservation VALUES ($id, $payment, $e-mail) Online Check-In SELECT RF.flightId,

Create Reservation INSERT INTO Reservation VALUES ($id, $payment, $e-mail) Online Check-In

Reservation VALUES ($id, $payment, $e-mail) Online Check-In SELECT RF.flightId, RF.flightDate FROM ReservationFlight RF

SELECT RF.flightId, RF.flightDate FROM ReservationFlight RF WHERE RF.reservationId = $Id

SELECT passengerId FROM ReservationPassenger WHERE reservationId = $rId

SELECT S.seatNo FROM Seat S WHERE S.flightId = $fId AND S.flightDate = $flightDate

INSERT INTO Seat VALUES ($passengerId, $fId, $fDate, $seatNo) 22

INSERT INTO Seat VALUES ($passengerId, $fId, $fDate, $seatNo)

Advanced Database Components

Reports

1. Show the number of flights that a pilot attended.

SELECT S.id, S.name. COUNT(*)

FROM Flies F, SystemUser S

WHERE S.id = Flies.pilotId

GROUP BY S.id

2.Show the number of flights that a cabin attendant attended.

SELECT S.id, S.name, COUNT(*)

FROM Flies F,SystemUser S

WHERE S.id = CabinAttendant.id

GROUP BY S.id

3. Number of passengers of all flights with a given flight number between two given dates.

SELECT F.date COUNT(S.id)

FROM Flight F, Seat S

WHERE F.flightId=$flightId AND F.date >= $bdate AND F.date <=$edate AND S.flightId=$flightId

GROUP BY F.date

4.

Average number of passengers of all flights with a given flight number between two given dates.

SELECY AVG(Temp.cnt)

FROM

(SELECT F.date, COUNT(S.id) as cnt

FROM Flight F, Seat S

WHERE F.flightId=$flightId AND F.date >= $bdate AND F.date <=$edate AND S.flightId=$flightId

GROUP BY F.date) as Temp

5. Number of all passengers between two given dates.

SELECT COUNT(*)

FROM Flight F, Seat S

WHERE F.flightId = S.flightID AND F.date >= $bdate AND F.date <= $edate

6. All plane models that at least one pilot can fly

SELECT PM.id, PM.name

FROM PilotHasLicence PL, LicenceForPlane LP, PlaneModel PM

WHERE PL.licenceId = LP.licenceId AND LP.modelId = PM.id

Constraints

1. Number of seats in a flight cannot exceed the capacity of that flight's pilot.

2. A flight's landing time must be later than its departure time

3. A flight's landing city must be different from its departure city

4. A pilot that flies a plane must have a license to fly that plane.

Triggers

1. When a flight created its remaining seat attributes will be taken from related plane model.

2. When a reservation made the flight's remaining seat attribute for that class should be decreased by one.

Stored Procedures

1. The price of a reservation will be determined on the fly, depending on the number of remaining seats in flight, distance of the flight and how many days left to the flight.

Views

1. All passengers that have been flied at least 50 times in 2010 for promotions or gifts.

CREATE VIEW MostFliedPassengers (name,count)

AS SELECT Temp.name, Temp.cnt

FROM

(SELECT P.name, COUNT(*) AS cnt

FROM Passenger P, Seat S

WHERE P.id = S.passengerId AND S.flightDate >= 01/01/2010 AND S.flightDate <

01/01/2010

GROUP BY P.name

) AS Temp

Implementation Plan

We will use MSSQL Server as DBMS. It satisfy modern features like triggers constraints and views

We will develop system on ASP.NET framework using C#

ER Diagram for Database

ER Diagram for Database 27