You are on page 1of 40

Table of Contents

1.0 Design........................................................................................................................................3

1.1 Entity Relationship Diagram (Crow’s Foot Notation)...........................................................3

1.2 Entity Relational Model.........................................................................................................4

2.0 Optimization Strategy..............................................................................................................14

2.1 Denormalization..................................................................................................................14

2.1.1 Merging One-to-One Relationship...............................................................................14

2.1.2 Foreign Key Duplication..............................................................................................17

2.2 Natural Key over Surrogate Key.........................................................................................18

3.0 Constraint.................................................................................................................................19

3.1 Primary Key.........................................................................................................................19

3.2 Foreign Key.........................................................................................................................20

3.3 Not Null...............................................................................................................................20

4.0 Trigger.....................................................................................................................................21

4.1 Reservation Itinerary Changes.............................................................................................21

4.2 Aircraft Travel Class Seats..................................................................................................22

4.3 Reservation Itinerary Baggage Limit...................................................................................23

5.0 Stored Procedure......................................................................................................................24

5.1 Get Route Fare for Passenger Type.....................................................................................24

5.2 Book One way Round Trip..................................................................................................26

6.0 Individual Query......................................................................................................................27

6.1 Member 1 (Yong Chi Fei – TP039618)...............................................................................27

6.1.1 Query 1.........................................................................................................................27

6.1.2 Query 2.........................................................................................................................27

6.1.3 Query 3.........................................................................................................................28

1|Page
6.1.4 Query 4.........................................................................................................................28

6.1.5 Query 5.........................................................................................................................29

6.1.6 Query 6.........................................................................................................................30

6.1.7 Query 7.........................................................................................................................30

6.2 Member 2 (Cheong Yi Wei – TP040510)...........................................................................31

6.2.1 Query 1.........................................................................................................................31

6.2.2 Query 2.........................................................................................................................32

6.2.3 Query 3.........................................................................................................................33

6.2.6 Query 6.........................................................................................................................34

6.2.7 Query 7.........................................................................................................................35

6.3 Member 3 (Aaron Abinson Alagan – TP038692)...............................................................36

6.3.1 Query 1.........................................................................................................................36

6.3.2 Query 2.........................................................................................................................36

6.3.3 Query 3.........................................................................................................................36

6.3.4 Query 4.........................................................................................................................36

6.3.5 Query 5.........................................................................................................................36

6.3.6 Query 6.........................................................................................................................36

6.3.7 Query 7.........................................................................................................................36

7.0 Personal Reflections................................................................................................................37

7.1 Yong Chi Fei – TP039618...................................................................................................37

7.2 Cheong Yi Wei – TP040510................................................................................................38

7.3 Aaron Abinson Alagan – TP038692....................................................................................39

2|Page
1.0 Design
1.1 Entity Relationship Diagram (Crow’s Foot Notation)

3|Page
4|Page
1.2 Entity Relational Model

5|Page
6|Page
7|Page
8|Page
9|Page
10 | P a g e
11 | P a g e
12 | P a g e
13 | P a g e
14 | P a g e
2.0 Optimization Strategy
2.1 Denormalization
2.1.1 Merging One-to-One Relationship

Figure 1: Unoptimized MealOption table

One of the optimization strategies that was utilized in the development of the Travel Safe
International (TSI) database system is denormalization of the database by merging the one-to-
one relationship table. This example is demonstrated on the unoptimized MealOption table and
Drink table. The unoptimized table utilize two table which resulted a drawback in the
relationship of the table as it increases the join relationship between the table. Due to this, the
retrieval of the drink information will require the user to access the MealOption table before
accessing the Drink table. Hence, the denormalization approached was selected for the scenario.
By doing so, the report generation for the following table will be slower due to the nature of
normalized table that has multiple join statement.

15 | P a g e
Table 1: Unoptimized Approach (MealOption, Drink)

MealOption Drink
Id (PK) Id
MealOptionName DrinkName
MealOptionDescription
MealOptionDrinkId (FK)
AirlineCode (FK)
MealId (FK)

The table above show the unoptimized approach of handling the MealOption table and
Drink table. This approach resulted in more table and join statement between the table which
causes lower performance due to slower data access.

Figure 2: Merging One-to-One Relationship

The figure above is the output of the denormalization for the MealOption approach. The
approach can be done by merging the MealOption table and Drink table. By doing so, the
database can minimize the join statement which can result in faster retrieval of MealOption data
as it has lesser join relationship. In addition, it also makes the usage of the query for the retrieval
of data easier as it has lesser table which promote better usability.

16 | P a g e
Table 2: Optimized Approach (MealOption)

MealOption
Id (PK)
MealOptionName
MealOptionDescription
MealOptionDrink
AirlineCode (FK)
MealId (FK)

The table above is the output of optimizing the MealOption table and Drink table by
merging them altogether. The table above show one table instead of two table which reduces the
total amount of table and join statement between the table.

17 | P a g e
2.1.2 Foreign Key Duplication

Figure 3: Foreign Key Duplication

Another way of optimizing a database is by duplicating the foreign key in the table. This
approach is utilized when the user wants to access the specific table, but they will be required to
access another table first before accessing the specific table that they want. This scenario will be
resulted in slower performance as data retrieval from the specific table will require access from
another table. Hence, the duplication of the foreign key will ensure that the performance of the
query can be faster and more efficient. For example, this approach is utilized in the Flight table
which allow for faster performance as the access of the data is easier when it can be done from
the (Flight -> Airline) instead of (Flight -> AirlineRoute -> Airline). By doing so, the data access
can be speed up as the access to the airline is shorten by one table access.

18 | P a g e
2.2 Natural Key over Surrogate Key

Figure 4: Surrogate Key (Country)

Another optimization strategy that was utilized for the development of the database is the
usage of natural key over surrogate key. Surrogate key is a type of primary key that is artificially
generated value that is normally in numeric value in runtime while a natural key is commonly
referred when the primary key is made up of real data that is meaningful. In the beginning of the
database development, surrogate key was utilized for the Country table which allow for the
creation of a separate Country table that can be used to ensure that the country names are
accurate. However, utilizing surrogate key in the following scenario will only add more join
statement for the query when the system tries to get the countryName.

Figure 5: Natural Key (Country)

Hence, the replacement of the surrogate key with natural key is a better decision in
optimizing the database as natural key is meaning which means they can be used for searching
easier when compared to surrogate key when it comes to this scenario as country name is the
only attribute in the table and it is always unique. In addition, natural key of the CountryName is
essentially easier for searching when it compared to surrogate key approach of automatically
generating numeric value.

19 | P a g e
3.0 Constraint
3.1 Primary Key

Figure 6: Primary Key Constraint (Meal)

Constraint are the rules that can enforced the data column of the designated table. By
doing so, the insertion of the data will be enforced by the type of constraint that was put in
placed for the table. This can ensure better accuracy and reliability as the insertion of the data
will be enforced by such constraint.

Based on the database design, the Meal table has a Primary Key constraint that can be
used to uniquely identify each of the meal record in the database table. By doing so, the
searching for the mealName can be done by matching the Primary Key of the meal with the
appropriate Foreign Key.

20 | P a g e
3.2 Foreign Key

Figure 7: Foreign Key Constraint (Airport)

Another constraint that was utilized for the database design is by using Foreign Key to
uniquely identify a record in any of the database table. For example, this can be done by
matching the Foreign Key of the Airport table with the City table. The Foreign Key cityCode
references the cityCode Primary Key from the City table.

3.3 Not Null

Figure 8: Not Null Constraint (Aircraft)

Another constraint that was utilized in the database design is the Not Null constraint
which enforce the column to not being able to accept any NULL values. By doing so, the
insertion of a new record can only be done when the enforced field of the column contain a
value, if any of the column that was enforced with the Not Null constraint does not contain any
values, the insertion of the record will also be aborted.

21 | P a g e
4.0 Trigger
4.1 Reservation Itinerary Changes

Figure 9: Reservation Itinerary Changes Trigger

The following trigger is the trigger for handling the reservation itinerary changes. The
trigger will check for the inserted value whether the new flight schedule is still within the ticket
validity. An error message will be fired if the ticket validity is already expired.

Figure 10: Trigger Error Message

22 | P a g e
4.2 Aircraft Travel Class Seats

Figure 11: Aircraft Travel Class Seats

The following trigger is stored in the AircraftTravelClass table and it will check and
compare the total amount of seats from an aircraft and then compare it to the sum of the travel
class seats that the aircraft provide. For example, the total amount of seats from the Business,
Premium and Economy class must not exceed the total amount of seats in an aircraft.

Figure 12: Trigger Error Message

If the inserted value does not adhere to the logic, the error message will be fired from the
trigger.

23 | P a g e
4.3 Reservation Itinerary Baggage Limit

Figure 13: Reservation Itinerary Baggage Limit

The following trigger is stored in ReservationItineraryBaggage class and it will trigger an


error message when the total baggage limit exceeded the threshold such as 40 kg for a single
booking.

24 | P a g e
5.0 Stored Procedure
Stored procedure is a prepared SQL code that allow the user to save and reuse it
whenever they want. The stored procedure will allow the user to pass parameters into the stored
procedure so that the stored procedure can act based on the parameter value that is passed. The
reason of using stored procedure in SQL is because it consists of programming statements that
perform operations in the database, including calling other procedure. Besides, it could return a
status value to a calling procedure or batch to indicate success or failure. There are several
benefits of using stored procedure which is it allow modular programming, allow faster
execution on operation statement, reduce network traffic and used as a security mechanism.

5.1 Get Route Fare for Passenger Type

Figure 14: Stored procedure of get route fare for different passenger type

Figure above shows one of the stored procedures that is applied into this assignment. It
used to determine the fare for different passenger such as infant, child, youth, adult, and senior.
The stored procedure is created, and three parameters is used to capture the input such as

25 | P a g e
passengerType, airlineRouteId, and fare. There is also an IF ELSE statement is used in the stored
procedure to determine the route fare based on the passenger type.

Figure 15: File that save stored procedure

Figure above shows where the stored procedure saves, and user could execute this line
‘exec USP_GET_ROUTE_FARE_FOR_PASSENGER_TYPE;’ to run the stored procedure.

26 | P a g e
5.2 Book One way Round Trip

Figure 16: Stored procedure of booking roundtrip

Figure above shows a stored procedure that used to book round trip. Three parameters are
used in this stored procedure, which is reservationType, departureFlightScheduleId, and
returnFlightScheduleId. Next, insert the id, reservationDate, reservationStatus and
reservationType into the Reservation table. IF statement is used in this stored procedure to check
the reservationType or returnFlightScheduled. If one of the conditions meets, then the next line
of command will proceed and set the @returnFlightScheduled as null. All the data is requiring
inserting into the ReservationItinerary table.

27 | P a g e
6.0 Individual Query
6.1 Member 1 (Yong Chi Fei – TP039618)
6.1.1 Query 1
Create a query which shows direct flights only for given dates, source & destination.

Figure 17: Query 1

6.1.2 Query 2
Create a query which shows aircraft code, class code, and expected revenue for each class code,
along with the total revenue of each aircraft for a given airline in a single journey.

Figure 18: Query 2

28 | P a g e
6.1.3 Query 3
Create a query which shows all passenger numbers with their corresponding descriptions of
reservation status for a specific airline.

Figure 19: Query 3

6.1.4 Query 4
Create a query which shows the name of airline that has been most frequently travelled through
by the passengers for specified source and destination in given range of dates.

Figure 20: Query 4

29 | P a g e
6.1.5 Query 5
Create a query which provides, for each age category of passengers, the following information:

The total number of infants, children, youths, adults & seniors travelling through specified flight
in a single journey operated by a specified airline in given date. Result should contain both
detailed breakup & summary for above mentioned categories along with overall summary.

Figure 21: Query 5: Part 1

Figure 22: Query 5: Part 2

30 | P a g e
6.1.6 Query 6
Create a query which shows the airline name offering maximum number of journey routes along
with names of source and destination.

Figure 23: Query 6

6.1.7 Query 7
Create a query to show the airline name that offer the number of meal type based on the type of
food category.

Figure 24: Query 7

31 | P a g e
6.2 Member 2 (Cheong Yi Wei – TP040510)
6.2.1 Query 1
Query to display flight details such as the aircraft code, regular fare, and discounted fare for the
first class. A 25% discount is being offered. Label the columns as Aircraft, Regular First-Class
fare, and Discounted First Class fare.

Figure 25: Queries to display 25% offer for first class

The figure above shows a stored procedure that used to filter the first-class customer and
calculate the different price after a 25% deduction. Select the aircraftID, travelClass,
travelClassFare from AircraftTravelClass table. Furthermore, assigned the new column to
aircraftID as ‘Aircraft’, travelClassFare as ‘Regular First Class Fare’ and the travelClassFare as
‘Discounted First Class Fare’ after deduction 25% of total fare. The WHERE clause is used to
filter the records by travel class of ‘first’. Figure below shows a result after executing the stored
procedure.

Figure 26: Result of the price different

32 | P a g e
6.2.2 Query 2
Query to display the sorted details of flights to given city code with the least duration flight
displayed first.

Figure 27: Query to display the sorted flight according to the given country

The figure above shows a set of stored procedure that is used to sort the flight details in
ascending order by given city code. Selected id, airlineCode, flightType, flightNumber,
originAirportCode, duration from two different table which is Flight and AirlineRoute. Used join
keyword to join between this two table based on the foreign keys such as Flight.airlineRouteId.
On the other hand, a parameter is used to allow the caller to pass the specific city code to the
stored procedure. The WHERE is used to sort the flight details by ascending order. The figure
below shows the result after executing the stored procedure.

Figure 28: Result after executing the stored procedure

33 | P a g e
6.2.3 Query 3
Query to display the types of non-vegetarian meals offered on flights.

Figure 29: Query to display Non-vegetarian Meals

The figure above shows a stored procedure to display the Non-vegetarian meals that
offered on flights. Selected the id, foodCategoryName, foodCategoryId, mealOptionId,
mealOptionName from three different table which is FoodCategory, MealOptionFoodCategory,
and MealOption. Besides, used the join keyboard to join between three table based on the foreign
key such as FoodCategory.id and MealOptionaFoodCategory.mealOptionId. The Where clause is
used to filter the foodCategoryName. Below shows a result after executing the stored procedure.

34 | P a g e
6.2.6 Query 6
Create a query which shows the details of passengers who have availed any extra services for a
given flight on specified date.

Figure 30: Query to show the names of meal options available on the given airline

The figure above shows the stored procedure that is used to shows the name of the meal
options available on the given airline. A parameter is used to allow the caller to pass the specific
airline name to the stored procedure. Next, select airlineName, carrierCode, mealOptionName,
airlineCode from two different table such as Airline and MealOption. The join keyword is used
to join two table based on the foreign key such as Airline.carrierCode. The Where clause is used
to filter based on the airline name that inserted by user. The figure below shows the result after
executing the stored procedure.

Figure 31: Result of meal options available on the given airline

35 | P a g e
6.2.7 Query 7

Figure 32: Query of filter and sum up schedule flight in specific date time

The figure above shows a stored procedure that used to find out how many flight that is
scheduled in a given date. The flight details such as id, airlineCode, flightType, flightNumber,
airlineRouteId, flightId, departureDateTime from two different table which is Flight and
FlightSchedule. A parameter also created for passing date into the stored procedure. The join
keyword is used to link two table based on the foreign key such as Flight.aircraftId. The Where
clause is used to filter the departureDateTime of the flight. Meanwhile, the a rollup statement is
applied to the store procedure to calculate the total number of flight that is schedule in the
specific date.

36 | P a g e
6.3 Member 3 (Aaron Abinson Alagan – TP038692)
6.3.2 Query 2

6.3.3 Query 3

6.3.4 Query 4

6.3.6 Query 6

37 | P a g e
7.0 Personal Reflections
7.1 Yong Chi Fei – TP039618
For this group project, the project team was tasked with the job of developing a database
solution for the Travel Safe International. Throughout the course of the development, the project
team was required to fulfill the business requirement of the case study by creating an Entity
Relationship Diagram (ERD). Aside from that, multiple optimization strategies were researched
and discussed as it can be useful in reducing the complexity of the database.

During the course of developing the database, the project team encounter many
difficulties while solving the business constraint and creating the appropriate database that fit the
real-life scenario of booking a flight. Hence, the database system encounter setback which
resulted an overly complex database that present a difficulty when it comes to database
documentation.

As for the personal SQL queries, it encounters minor setback due to the complexity of the
database. The complexity of the database can be both good and bad as the database design are
built to reflect the actual scenario of booking a flight while at the same time, it prove to be a
challenge to our individual query components as it will require time to slowly understand and
breakdown the database to smaller components. Due to this, the individual query will require
deeper understanding of the entire database design.

To conclude the reflection on this group project, the project presented an interesting
approach in developing an advanced database solution for the case study. Hence, the group
project allows for a deeper understanding into the development of an advanced database with
multiple individuals with different set of skills that they can provide to the project.

38 | P a g e
7.2 Cheong Yi Wei – TP040510
This assignment has helped me gain a lot of knowledge and information about database
system. As this is a group assignment, it also helped me a lot to work in groups as well. Together
working with my teammates, I learned a lot about Entity Relationship Diagram (ERD) and
normalizations as well. These diagrams were based on the case study which was given to the
group as an assignment.

Each member was given a set of 7 statements upon which queries had to be implemented.
The 7 statements I chose had given me a lot of knowledge and gained much information about
database systems and queries. I appreciate my group members for their time and effort and most
of all, their help to complete this assignment. I have learned a lot from them and new things such
as rollup and cube statements.

Apart from what the lecturer taught us in the classes, this group assignment enlightened
me with the importance of standard procedures, and trigger like statements to a database. Stored
procedures provide a new table to let a user store some important attributes. Trigger is a rule that
allows the user to access, insert, update or delete some data. In addition, one really important
command I learned is the CAST command which helps in situations like changing datetime data
type to a float, decimal or an integer.

39 | P a g e
7.3 Aaron Abinson Alagan – TP038692
Throughout this module and assignment, I have achieved a good understanding of the
database lifecycle. In the earlier stages of the module, I was introduced to the SQL language and
its fundamentals. Therefore, throughout this module and assignment, I have mastered the SQL
language and have applied it in my assignment. Moreover, by mastering the SQL language, I
have successfully created the DDL and DML of the assignment with my teammates. I also assure
that all data and records in the database is accurate. Furthermore, I have also applied Triggers in
the assignment to improve the performance of the database by speeding up the data retrieval
process. Store procedures are implemented in the assignment to accept parameters being input
and return multiple values from the output.

In terms of database design, I have also constructed an ERD using 3 rd Normal Form of
the database with my teammates. The entities, attributes and relationship between entities are
shown in the ERD. To optimize the database, various optimization strategy are applied in the
database design that are denormalization by merging a one to one relationship table, foreign key
duplication and usage of natural key over surrogate key.

Various queries have also been covered in this assignment. The query and the results
generated have also been documented. Lastly, I would like to extend my gratitude and thanks to
my fellow teammates, Cheong Yi Wei and Yong Chi Fei for helping me throughout this
assignment. I would also like to sincerely thank my lecturer, Mr. Abdallah S.M. Alnatsha for
guiding me throughout the module and assignments by resolving all doubts that I have
encountered.

40 | P a g e

You might also like