Sei sulla pagina 1di 36

Advanced Database |1

CT004-3-3-ADVBS

ADVANCED DATABASE GROUP ASSIGNMENT


TITTLE:

TRAVEL SAFE INTERNATIONAL

INTAKE: UC3F1208 STUDENT NAME: JUMAA SALIM [TP023161] SASHI KUMAR [TP014682] FADHILI SHABANI SINGA [TP026366]

LACTURER NAME: MR VAZEERUDEEN ABDUL HAMEED

Advanced Database |2

Table of Contents
Introduction Assumption/Business Rules Design Entity Relation Diagram Relationship Schema Relationship Diagram Optimization Strategies Indexing of the database table column Constraints NOT NULL Constraint Primary Key Constraint Triggers Update Total trigger Update Time trigger Implementation T-SQL TEST STRATEGY Queries Member 1 Member 2 Member 3 Conclusion Personal Reflection Member 1 Member 2 Member 3 Workload Matrix References Appendix 3 4 4 5 6 7 7 7 8 8 9 9 9 10 11 11 12 16 16 17 22 25 25 25 27 27 28 29 30

Advanced Database |3

Introduction With the advancement of information systems from around the world, there would be no surprises from complexities growing when storage aspect comes into place. Most of the resilient systems that handle heavy transactions daily are structured from their design to operate at complicated scenarios with much robustness and little overheads. Users expectations are high and they want to see what they think they should see and no otherwise. Airline companies are no exception to this rule. TSI involvement in production of systems to meet the global user demands must cater for all is expected from their customers. TSI being the one of the leading players in the market for provision of distribution system to serve airline ticketing transactions from booking to revenue collection on each flight operations makes a great challenge. However, the technology favors all if used effectively. Engaging relational database management system tools to handle such transactions facilitates the smooth operations; however, its design structure must meet the great requirements of the real environment. Meeting business logic is one core importance and so the proposed database design must fit well within the pre-existing systems to integrate with this design. The design structure will reflect the Flight reservations, Cancellation and Rescheduling. Among the many, its logic design must ensure that expected output is per requirements and data redundancies are suppressed to ensure proper performance. The database queries are part of the challenges, however, if effectively designed to meet the system transactions at any particular time will ensure the whole system efficiency. To mention a few objectives, the queries need; To enable customers to book tickets according to classes. To provide selection of flight trip option such as One-way, Round-trip and Multi-city. To enable provision of type meal services according to time schedules and flights. To enable user books special services such as child care. To reflect fare prices according to age rate. To display flight codes and passengers booking details at any point. To operate with minimal overheads during peak.

Advanced Database |4

There is quite a lot to implement within the database; however, Microsoft SQL Server with great capabilities of relational database management system has been selected to support the design and implementation of the system.

Assumption/Business Rules Requirements were provided to reflect the real environment business scenario; however, some other areas need to be assumed so as to meet the requirements beforehand and hence are outline below; There is no need to consider concurrency, legacy or network issues. There will be no need to deal with company other operations outside the database. Assume that only 4 travelers per each booking. The development will not consider flights seat arrangements as each company sets out their own arrangements, but its structure will be flexible to meet such. Other than the airline restriction provided, the development will not account for any inclusions from other areas.

Design Creation of logical design will help the developers and users understand the flow of the storage engine which makes it better to implement and in case of any changes, then logical mapping can be used to correct the mistakes before the real implementation is committed on the database.

Advanced Database |5

Entity Relation Diagram


Infant Child
M 1 M N

Youth Adult Senior

d
1

Passenger
1 1

Selects

Destination

Contains
M M

Schedule

Books
M

Cancels
M

Pays
M 1

Payment

Receives

Includes Reservation
M N M

Traces

Determines
1

Provides

Meal
M

M M 1 M 1

Flight
1

Assigns
1

Plane

Has

Airlines
1

Carries
M M M

Provides

Service

Provides

Baggage

This diagram illustrates the relationship of entities in the database and how their share their information.

Advanced Database |6

Relationship Schema

This relationship schema illustrates the brief information about each table. It includes a set of column names, data types associated and name for the entire table.

Advanced Database |7

Relationship Diagram
Adult

Youth

FK1

Company Job P_ID

Senior

FK1 Child

Remark P_ID PK

Passenger P_ID P_Name P_IC P_Phone P_Email P_Birthday P_Gender DateJoin Status P_Passport P_Address P_Country Category

FK1

Type P_ID

FK1

Remark P_ID Infant

Schedule Destination PK D_ID D_Name D_Description D_Remark Dest_Schedule PK DS_ID DepartDate ArrivedDate D_ID S_ID PK S_ID Duration

FK1

Type P_ID

Reservation PK Flight PK F_Code F_Duration F_DepartLoc F_DepartTime F_ArriveLoc F_ArriveTime Plane_ID Sv_ID FK1 FK2 FK3 FK4 R_Code R_Quatity R_Option R_Class R_Remark F_Code P_ID DS_ID Pay_ID FK1 FK2

Payment PK Pay_ID Pay_Type Pay_Amount Date P_ID

FK1 FK4 Flight_Meal

Payment_Airline PK PA_ID Delivered Total Pay_ID A_ID

FK1 Service

FK1 FK2

F_Code M_ID Baggage PK Meal Bag_ID Bag_Description Bag_Weight Bag_Remark F_Code

PK

Sv_ID Sv_Name Sv_Type Sv_Remark A_ID Airline PK A_ID A_Name A_Contact A_Description A_Email A_Address

FK1 FK2

FK1

PK

M_ID M_Name M_Type M_Description FK1

Plane PK Plane_ID Plane_Name Plane_Capacity Plane_Remark A_ID

FK1

Optimization Strategies Indexing of the database table column We need to create primary key in every table of the database. When we create a primary key in a table, a clustered index tree is created and all data pages containing the table rows are physically sorted in the file system according to their primary key values. Each data page contains rows which are also sorted within the data page according to their primary key values. So, each time we ask any row from the

Advanced Database |8

table, the database server finds the corresponding data page first using the clustered index tree and then finds the desired row within the data page that contains the primary key value (Syedur Rahman, A. M. Ahsan Feroz, Md. Kamruzzaman and Meherun Nesa Faruque, 2010). This introduces us to B+ Tree (Balances Tree). The use of intermediate nodes with values ranges and instructs the database Structure Query Language engine of where to look for during its search for specific index values within the tree and obviously starting with the root node. From definition, leaf nodes contain actual index values. However, if this is a clustered index tree, the leaf nodes are the physical data pages and when its non-clustered index tree, the leaf node contain index values along with clustered index keys (Syedur Rahman, A. M. Ahsan Feroz, Md. Kamruzzaman and Meherun Nesa Faruque, 2010). According to TSI requirements this will improve the effieciency as fetching the data from the database will be much quicker than tradition way because when searching for specific data in the database will first check the tree and then actuall jump to actual row and hence little time taken to retrieve the results. Thus, in general indexing will improves data retrieval in the database. Constraints NOT NULL Constraint From the database view, when this constraint is declared it makes the column be mandatory meaning the user cannot insert a row in the table without valid data type been provided. Its merely a restriction to the column and end with cardinality of 1...1.From TSI system requirements the database needs to filter and make other key data mandatory. When customers book for flight trips without providing their name, then the query will need to generate error and alert since without customer name then it will had to define the ticket being booked as each customer is defined by ID number. The example below shows a sample code for reservation table.

create table Reservation ( R_CODE int primary key IDENTITY (1,1), R_Quatity int not null, "Date" datetime not null, R_Option varchar(50), R_class varchar(50),

Advanced Database |9

R_Remark varchar(100), F_Code int FOREIGN KEY REFERENCES Flight(F_Code) not null, P_ID int FOREIGN KEY REFERENCES Passenger(P_ID) not null, DS_ID int FOREIGN KEY REFERENCES "DestinationSchedule"(DS_ID) not null, Pay_ID int FOREIGN KEY REFERENCES Payment(Pay_ID) not null ); Primary Key Constraint This constraints is used to make sure that eat row is uniquely identified in the table. From the baggage table, each bag will be created with an unique id to only represent all information concerning that bag for the customer. The sql sample illustrates below create table Baggage ( Bag_ID int primary key IDENTITY(1,1), Bag_Description varchar(100) not null, Bag_Weight int not null, Bag_Remark varchar(100), F_Code int FOREIGN KEY REFERENCES Flight(F_Code) not null ); Triggers A trigger is a special kind of stored procedure that automatically executes when an event occurs in the database server. DML triggers execute when a user tries to modify data through a data manipulation language (DML) event. DML events are INSERT, UPDATE, or DELETE statements on a table or view. These triggers fire when any valid event is fired, regardless of whether or not any table rows are affected (Microsoft SQL, 2007). Update Total trigger The trigger is used to add all the modified or newly inserted payment data into the total amount that is on PaymentAirline table. This kind of trigger operates in Flight and PaymentAirline tables

DROP TRIGGER update_total GO CREATE TRIGGER update_total ON Payment AFTER INSERT,UPDATE

A d v a n c e d D a t a b a s e | 10

AS IF UPDATE (Pay_Amount) BEGIN DECLARE @Pay_ID INT DECLARE @old_Pay_Amount INT DECLARE @new_Pay_Amount INT

SELECT @old_Pay_Amount = (SELECT Pay_Amount FROM deleted) SELECT @new_Pay_Amount = (SELECT Pay_Amount FROM inserted) SELECT @Pay_ID = (SELECT Pay_ID FROM inserted)

UPDATE "PaymentAirline" SET Total = Total + @new_Pay_Amount - @old_Pay_Amount FROM inserted AS I JOIN "PaymentAirline" AS U ON U.Pay_ID = I.Pay_ID END; Update Time trigger This trigger does modify and automatically change all the remarks of the plane that are scheduled to delayed status in case the arrival time of the airplane is delayed. DROP TRIGGER update_Time GO CREATE TRIGGER update_Time ON Flight AFTER UPDATE AS IF UPDATE (F_ArriveTime) BEGIN UPDATE Reservation SET R_Remark = 'Delayed' FROM inserted AS I JOIN Reservation AS U ON U.F_Code = I.F_code

A d v a n c e d D a t a b a s e | 11

END;

Implementation T-SQL

DROP FUNCTION TraceRecords GO CREATE FUNCTION TraceRecords ( @Name varchar(50) ) RETURNS @CustomerRecord table ( P_ID int, P_Name varchar(50), P_IC varchar(19), P_Passport varchar(30), P_Phone varchar(30), R_Class varchar(50), D_Name varchar(50), Pay_Type varchar(50), P_Amount int, PA_ID int, A_ID int, A_Name varchar(50) ,DepartDate datetime, ArrivedDate datetime, F_DepartLoc varchar(90),F_ArriveLoc varchar(90) ) AS BEGIN INSERT INTO @CustomerRecord SELECT P_ID = P.P_ID,

P_Name, P_IC, P_Passport, P_Phone, R_Class, D_Name, Pay_Type, Pay_Amount, PA_ID,

A d v a n c e d D a t a b a s e | 12

A_ID = Air.A_ID, A_Name, DepartDate, ArrivedDate, F_DepartLoc, F_ArriveLoc FROM [Airline].[dbo].[Passenger] AS P INNER JOIN [Airline].[dbo].[Reservation] AS R ON P.[P_ID]= R.[P_ID] INNER JOIN [Airline].[dbo].[DestinationSchedule] AS DS ON R.DS_ID = DS.DS_ID INNER JOIN [Airline].[dbo].[Destination] AS D ON DS.D_ID = D.D_ID INNER JOIN [Airline].[dbo].[Payment] AS Pay ON P.[P_ID] = Pay.[P_ID] INNER JOIN [Airline].[dbo].[PaymentAirline] AS PA ON Pay.[Pay_ID] = PA.[Pay_ID] INNER JOIN [Airline].[dbo].[Airline] AS Air ON PA.[A_ID] = Air.[A_ID] INNER JOIN [Airline].[dbo].[Flight] AS F ON R.[F_Code]= F.[F_Code] WHERE P_Name = @Name RETURN END

TEST STRATEGY Testing is conducted on our database to validate and verify the data based on some perspectives, such as the data integrity, data validity, performance of the database and testing the procedure, triggers and functions created. Before the entire test conducted, at the very first beginning, all the business rules and constraints have to be identified from the scenario given. After that, all the tables have to be identified and attribute listed well from the case study in ERD. In this case, discussion and brainstorming technique were used to respond the correctness of the Entity Relationship Diagram. After that, the normalization of 3NF is used to reduce any data redundancy in the ERD. After all the tables are been identified and attributes

A d v a n c e d D a t a b a s e | 13

listed well, now the selection on optimization strategy and triggers can be conducted. We have to find out which optimization strategy is the best to be conducted to test on the performance and efficiency of our database. At last we had chosen the indexing and de-normalization. While for the triggers, there are many triggers can be performed. We have to select the two triggers from the scenario that support the business rules. The business rules must able to bring the most benefit or impact and is realistic to be tested and implemented into our database. Lastly, we selected the two triggers, which will sum up the total of a payment based on the airline and update the remark of flight into delayed if the arrival time of the airplanes is delayed. Before the implementation part, we have to make sure all the design part for the tables and attributes are identified and listed well. After that, we will identify the priority of the tables; it means tables without foreign key will be created first into the database. Hence, when other tables require the references on the Primary Key, the database will show the required Primary Key as reference that the users need and no errors will be shown. Besides it, the length and data type for the attribute inside a table are almost needed to be predicted. Every ID for each table will be in integer format to allow them to be auto-increment, while for the datetime data type will be all the attributes that deals with date and lastly the varchar is used for the remaining attributes. Sometimes, the when we generating the data, we realized the length is not exactly what we had expected. So, in order to avoid this, we have increased the size for each attributes. After that, a series of realistic data have to be inserted into the database. Hence, a short application was developed in c#.net for the purposing of filling up the realistic data into the database. A series of possible data were prepared and listed in an array variable then it will be randomly retrieved from the array list and been inserted into the databases tables by looping. In order to make sure the data was inserted correctly into the database, a lot of testing and practices were conducted. The critical part of it was either the database was accessible with the application and connection between the database and application. There were a lot of errors and different ways were occurred and experienced, such as the method of taking the database offline, and then move and attached it into the c#.net application. However, a short coding with random array and for loop have also been tested well and successfully inserted into the database, but when replacing and overwriting the offline database with the filled database from c#.net, it has shown the error as listed.

Figure 1 Error Message 1

A d v a n c e d D a t a b a s e | 14

Figure 2 Error Message 2 So, an alternative way of connecting the database with the c#.net has to be researched and finally, a direct connection from the c#.net straight to the local links has been successfully linked. Figure below shows the when users trigger on the button, all the record will be generated and inserted into the database. Figure below shows the data list prepared into the array.

Figure 3 Coding sample 1 Figure belows show the looping to insert how many records will be generated into the database.

A d v a n c e d D a t a b a s e | 15

Figure 4 Coding sample 2

Figure below shows the connection to the database, and query to insert each variables from c#.net application into the tables column.

Figure 5 Coding sample 3 However, another issue has occurred. In order to insert the data that has data validation and data integrity, a lot of validation has been used together in the c#.net before the records were generated. Last we tried; the hardest validation was the validation on datetime. We have to round off the minute to hour when it exceed 60 minutes, and then minutes to hours, hours to days, days to months, and finally months to years. After all the records have been inserted well, now we are able to view on the triggers we have created as well as the T-SQL, are they functioning well or not. Lastly we have a completed database and tables that we can proceed to the queries question on assignment.

A d v a n c e d D a t a b a s e | 16

Queries Member 1 Create a query which shows direct flights only for given dates, source & destination. Select [F_DepartLoc],[F_DepartTime],[F_ArriveLoc],[FarriveTime] From [Airline].[dbo].[Flight] Go

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. Select Plane_ID, [R_class],[R_option],[F_DepartLoc],[F_ArriveLoc],[Pay_Amount] From [Airline].[dbo].[Reservation],[Flight],[Payment] Where [R_Option] = 'Round-trip' Go

Create a query which shows all passenger numbers with their corresponding descriptions of reservation status and query should also show the descriptions of reservation status that have not been assigned any passenger numbers. Select [P_ID],[P_Name],[P_Phone],[P_Passport],[F_Duration],[F_Departloc],[F_DepartTime],[F_Arriveloc], [F_ArriveTime],[Plane_ID] From [Airline].[dbo].[Passenger],[Flight] Go 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. Select Top 1 [A_Name],[F_DepartLoc],[F_ArriveLoc], count (*) From [Airline].[dbo].[Flight],[Airline] Group by [A_Name],[F_DepartLoc],[F_ArriveLoc] Order by count(*) Desc

A d v a n c e d D a t a b a s e | 17

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. Select [A_Name],[Category], count(Category) From [Airline].[dbo].[Airline],[Passenger],[Reservation] where [R_Option] = 'Round-trip' Group by [A_Name],[Category] With cube

Create a query which shows the airline name offering maximum number of journey routes along with names of source and destination. Select [A_Name],[R_Option],[D_Name] From [Airline].[dbo].[Reservation],[Airline],[Destination] Where [R_Option] = 'Multi-city' Go

Develop one additional query of your own which provides information that would be useful for the business. Marks will be awarded depending on the technical skills shown and the relevance. of the query. Select [Plane_Name],[F_DepartLoc],[F_DepartTime],[F_ArriveLoc],[F_ArriveTime],[Plane_Remark] From [Airline].[dbo].[Flight] Join [Plane] On [Flight].Plane_ID = [Plane].Plane_ID where [Plane_Remark] is not null Go Member 2 As we all know by using database, we can reduce the cost and improve operation by reducing redundancy. It also comes with widely distributed library. In current world almost every human in the world interact with database system. Millions of data transaction happens every second, so as we can

A d v a n c e d D a t a b a s e | 18

see database optimization is very important. In ms sql 2005 and ms sql 2008 we as the developer have option to optimize the query. Indexes As the developer if we use database index, we can have physical structure for the database table. By using index, it allows the user to find the particular section or to access the particular section of the database. This is very useful in large cooperate environment which handles huge numbers of data transaction. If a user need to search a record of 10,000 files in the database, this is going to take time and resources if there is no index in the database. If the database have index. The user just needs to search for the ID to find for the database.

Sample index command in ms sql SELECT FirstName, LastName FROM EMPLOYEE WHERE EmpID = 12345; By using a unique ID for the database, the user would be able to find the record without wasting time, this is also makes the database efficient and reduces the cost and time and energy. In the above situation, we can see that there are several thousand of employees, if the database dont have index. It will take time, energy and resources to find information regarding the particular employee. If the company has 100,000 employees, it is going to take very long time to search for the information of the individual .By using index, we able to find information about the employee using the unique ID had given to the employee. By using NULL in SQL, it will allow the user to insert or update the existing data without adding a value to the column. This will allow the field to save with NULL value. Regardless to the word NULL, it doesnt mean the value of the query is 0. We can use NULL value in database if there are large numbers of employee or data involved and cannot add a column in the table, instead, we add new table for the information. NULL is normally used in SQL to indicate value that doesnt exist in database, NULL is normally used as mathematic operator for unknown value or data which dont exist in database at all.

A d v a n c e d D a t a b a s e | 19

SELECT

AIRCRAFT, 'REGULAR 1ST CLASS' AS Expr1, 'DISCOUNTED 1ST CLASS' AS 1001 AS Expr1, 1002 AS Expr2, 1003 AS Expr3, 1004 AS Expr4

Expr2SELECT WHERE

(1001 = KL) AND (1002 = IPOH) AND (1003 = PNG) AND (1004 = JB) 'Fried Rice with Chicken Chettinad' AS Expr1, 'Mutton Biryani'

ORDER BY Expr1 DESC,SELECT

AS Expr2, 'Alpine Mushroom Pasta with Chicken Tikka' AS Expr3, 'Barbecue Portobello QuSELECT AUSTRALIA AS AUS, THAILAND AS THI, 'Fried Mutton Biryani'

SINGAPORE AS SG, AS NZD, TAIWAN AS TAI, JAPAN AS JSELECT AS Available, 'Alpine Mushroom Pasta with Chicken

AS Available, 'Chicken stake' AS AvailablePesadillas with Butter

In this source code is shows the flight company, flight ID, food ofred in the flight, flight destination. The developer design the particular details in the database query. This allow the user to reserve the ticket customer. Once in the flight, the customer can view the varity of dish avaible in the menu. This is very useful for the flight company and their business. This will allow the company to advertise and atrach more customer. NULL Result is NULL This is the source code for NULL. Sometimes this could lead into unpredictable result. Sometimes the operator might divide the NULL with zero. The operator might return NULL value instead In the result sets that are generated by the GROUP BY operators, NULL has the following uses: If a grouping column contains NULL, all null values are considered equal, and they are put into one NULL group. When a column is aggregated in a row, the value of the column is shown as NULL. The following example uses the GROUPING function to show the two uses of NULL. UNKNOWN replaces NULL in rows where the nulls in a column have been grouped. ALL replaces NULL in a column where NULL indicates that a column has been included in an aggregation. Null allow the user to insert or update the value without adding value to the column. This allow the

A d v a n c e d D a t a b a s e | 20

value to be saved as NULL. SELECT LastName,FirstName,Address FROM Persons WHERE Address IS NULL As we can see in the source code, the address is set to NULL. It can still allow the user to insert and update the table and the developer dont have to add any column. USE tempdb; GO CREATE TABLE dbo.GroupingNULLS ( Store nvarchar(19) ,SaleYear nvarchar(4) ,SaleMonth nvarchar (7)) INSERT INTO dbo.GroupingNULLS VALUES (NULL,NULL,'January') ,(NULL,'2013',NULL) ,(NULL,NULL,NULL) ,('Flight Active ',NULL ,'January') ,('Flight Active ','2013',NULL) ,('Flight Active ',NULL ,NULL) ,('Flight Active ',NULL,'January') ,('Flight Active ','2014','Febuary') ,('Flight Active ','2014',NULL) ,('Flight Summary','2013','January') ,('Flight Summary','2013',NULL) ,('Flight Summary',NULL,NULL) ,('Flight Summary','2014','January') ,('Flight Summary','2014','Febuary') ,('Flight Summary','2014','March');

SELECT ISNULL(Store, CASE WHEN GROUPING(Store) = 0 THEN 'UNKNOWN' ELSE 'ALL' END) AS Store

A d v a n c e d D a t a b a s e | 21

,ISNULL(CAST(SaleYear AS nvarchar(7)), CASE WHEN GROUPING(SaleYear)= 0 THEN 'UNKNOWN' ELSE 'ALL' END) AS SalesYear ,ISNULL(SaleMonth, CASE WHEN GROUPING(SaleMonth) = 0 THEN 'UNKNOWN' ELSE 'ALL'END) AS SalesMonth ,COUNT(*) AS Count FROM dbo.GroupingNULLS GROUP BY ROLLUP(Store, SaleYear, SaleMonth);

This is the source code used for NULL in SQL. This source code allows the user to retrieve the total flight on the particular date, with the entire details of the flight. The user can also view the summary of the flight based on the flight company and the overall summary of the flight details

CREATE TABLE #Flight ( ID UserID INT IDENTITY(1,1), INT,

UserName VARCHAR(50) )

INSERT INTO #Flight ( FlightID, FlightName ) SELECT FlightID = u.FlightID

,FlightName = u.FlightName FROM dbo.Flight f

A d v a n c e d D a t a b a s e | 22

CREATE CLUSTERED INDEX IDX_C_Users_UserID ON #Users(UserID)

CREATE INDEX IDX_Users_UserName ON #Users(UserName)

This source code is design by the devoloper to optimised the query. Each of the flight company and the plane is given an unique ID. This allow the user to search, alter and modify within his/her permission level. This makes the database query more useful for business because it is more eficient. The user dont have to waste time searching for information, the user just need to seach based on the unique ID to retrive the information regarding the flight.

Member 3 Create a query which shows the minimum, maximum, and average journey hours for flights to given city code. Display column headings as, Minimum duration, Maximum duration, and Average duration respectively. use AirlineReservation go

Select ci.CityID ,MIN(DATEDIFF(HOUR,Arrival,Departure)) as Minimum_Hour, MAX(DATEDIFF(HOUR,Arrival,Departure)) as Maximum_Hour, AVG(DATEDIFF(HOUR,Arrival,Departure)) as Average_Hour

from Flight f inner join Route r on r.RouteID=f.RouteID inner join Country co on co.CountryID = r.DestinationID inner join City ci on ci.CountryID=co.CountryID group by ci.CityID Create a query which shows the journey date, number of booked seats, and class name for given passenger.

A d v a n c e d D a t a b a s e | 23

use AirlineReservation go

Select f.Departure As Journey_Date, COUNT(pb.PID)as Booked_Seat, sc.SeatClassName from Flight f inner join FlightSeat fs on fs.FlightID = f.FlightID inner join dbo.PassangerBooking pb on pb.FlightSeatID = fs.FlightSeatID inner join SeatClass sc on sc.SeatClassID = fs.SeatClassID group by f.Departure, sc.SeatClassName

Create a query which shows the names of meals not requested by any passenger. use AirlineReservation go

Select m.MealDesc from Meal m Where m.MealID not in (Select f.MealID from Flight f) Create a query which shows the details of passengers booked through a specified airline in a given date for multi-city flights. use AirlineReservation go

Select * from PassengerBooking pb Where pb.BookingID = (Select b.BookingID from Booking b inner join Booking_Multicity bmc on bmc.BookingID = b.BookingID) The total number of unaccompanied children travelling in a given date. Result should contain both detailed breakup & summary for unaccompanied children for each airline along with overall summary. use AirlineReservation

A d v a n c e d D a t a b a s e | 24

go

Select count(fs.ServiceName) as Total_Unaccompanied_Children, f.Departure from FlightService fs inner join InFlightService ifs on ifs.ServiceID = fs.ServiceID inner join PassangerBooking pb on pb.PID = ifs.PassangerID inner join FlightSeat fst on fst.FlightSeatID = pb.FlightSeatID inner join Flight f on f.FlightID = fst.FlightID Group by f.Departure with rollup Create a query which shows the details of passengers who have availed any extra services for a given flight on specified date. use AirlineReservation go

Select * from Passenger p Where p.PID = (Select ifs.PassangerID from InFlightService ifs inner join FlightService fs on ifs.ServiceID = fs.ServiceID inner join Booking b on b.BookingID = ifs.BookingID ) Develop one additional query of your own which provides information that would be useful for the business. Marks will be awarded depending on the technical skills shown and the relevance of the query. use AirlineReservation go

Insert Route (RouteName,OriginID ,DestinationID ) Values ('JKT-SEO','1','6')

A d v a n c e d D a t a b a s e | 25

Conclusion In a nutshell, requirements are met and database structure will deliver the task specified. However, assumptions still kicks in to make a direction where exactly the database works best. Much efforts was done to make this structure fits the demand currently and future, but no guarantees are placed on the design as each companies tend to shift the objectives on their business in future, but for currently the database is well structured to meet the demand.

Personal Reflection Member 1 The nature of working together is about sharing, however, sharing depends on what perspective and it can be quite complicated when individuals from different countries that have different backgrounds, attitudes, ways of thinking and the core being different culture patterns altogether. During the course of delivering the tasks, the group was left hanging as every individual seems to have their thoughts on what to do, but they would not present it as how they would want it when doing it solo. Even when great ideas were presented to the group, the sole owner of the idea would not be able to explain fully and this attributes to the fact that language barriers seems to take its course. The complicated part is when ideas that lacked evidence or seems not to be a materialistic for proper consideration and worst when the idea owner cementing on their ideas to be considered as legit. After we agreed to working on the assignment, the group showed sufficient knowledge of the topic and this is attributed by the fact that we are all Information Technology students specializing in security. According to Tuckman`s model (The Happy Manager, 2007) which is significantly recognizes the fact that groups do not start off fully-formed and functioning. He suggests that teams grow through clearly defined stages, from their creation as groups of individuals, to cohesive, task-focused teams. Tuckman coined the oft-quoted terms: forming, storming, norming and performing. Through the Tuckman`s model, the group formation made us first to gauge our way of interacting to each other and even though we pretended to figure out the goals for the task, we were each finding

A d v a n c e d D a t a b a s e | 26

places in the group indirectly. Then the storming phase kicked in and we started purely to define each others ideas and how we do things. Some did not agree to other members ideas and its perfectly normal to disagree, hence comes the time when we decided to meet later and no one shows up. Lack of performance kicked in and every member did what they thought was right. However, after time went by we all realized that the assignment needs to be finalized and submitted on time, and so we came together and agreed on one idea. Thus, falling into norming phase under Tuckman`s model. Even though we reached performing phase by presenting on few keys areas like SWOT analysis of the idea. Later, we faced difficulties in presenting the information about. Beside Tuckman`s model, we however, used the social needs, the second phase in Maslow`s Hirechy of Needs which interprets that friendship and belonging has to be realized before each individual actually went for Esteem needs phase. Generally, it all comes down to motivation in getting the assignment done. On Tuckman`s model, it did makes understand and consider how we as each individual interacts with another when we are so much coming from different countries all together. For the group to have got the effectiveness and efficiency on our performance, we needed to undergo such criteria as outlines by Tuckman and Maslow. Although, by following Tuckman`s model, it felt that group was too liner and sequential and hopefully the group did not loop in some of the phases as this is a limitation of this model. On the overall, I feel the urge to make a huge improvement on myself even though we finally submitted the assignment. The group could have done much better and more effective than this. We wasted time on previous idea or proposal and in the end we had to find another solution within a limited time frame. If we had proper clearly defined guidelines, the progress would have been much smooth. The room for improvement is therefore necessary and come next time with group involvement, I would prefer to the assignment in this format; Setting up of clearly defined specific goals. The way our goals or objectives are should be measurable. Even though we disagree on certain matters, let the group be decisive on agreed upon approach. The processor chip idea was not realistic and we failed towards the middle of the assignment, hence, objectives should be more realistic on the topic chosen.

A d v a n c e d D a t a b a s e | 27

Time frame is core matter. These assignments are scheduled on specific intervals and we the group needed to think of the time. In a nutshell, am more privileged to have worked with my group mate on such assignment and even though we went through rough patches, it was necessary as a learning curve had to be realized and now am in a better position to fit in within collaborative works than only unleash a bucket of criticism as my excuses. Member 2 While we were working on this assignment, we had little other assignment to submit at the same time also. This put us under tremendous pressure. The exam was also around the corner, this gave us little time to study and work on the assignment. One of my team members was sick and we were unable to communicate with him. But luckily his health improved and he was able to contribute in the assignment. In this assignment I was able to learn more about database and query and how we can optimise the query. While doing this assignment, I was able to learn in depth about indexing of query database and the design of the indexing database. I also learn how to develop and design indexing query in MS.SQL. In this query I have design NULL query also. While design NULL query I have learn how NULL query works and the function of it. In this assignment I have also learn to design query and sort according to the destination, meals, duration of the flight. I have learnt to design query that can display flight details according to the flight code. Query that gave discount and allocates ticket to customer based of first class and regular class that. While working on the assignment, I have to learn to communicate more efficiently with my team members , I have learn to multi task and work on more than 1 task. While working in a team, we cannot predict anything and be certain of anything. We need to be ready any unexpected event that might occur

Member 3
FADHILI SHABANI SINGA TP026366. Based on the experience and group corperation that we had with the group members, I have learned a lot throughout the assignment period. SQL has a lot of routines or methods that can create altinate results. Thou it might not be the easiest program but its effects are great in range. The use of triggers, proceducers is a bit tricky. But functions like Rollup and cube generate various levels of details. I

A d v a n c e d D a t a b a s e | 28

strongly feel the more time kept for practicing sql will lead to simpler methods of managing data bases.

Workload Matrix Jumaa TP023161 EERD NORMALISATION DATABASE DESIGN BUSINESS RULES OPTIMAZATION STRATEGY 1. INDEXING 2. 3. CONSTRAINTS [a] NOT NULL [b] [c] PRIMARY KEY TRIGGERS [a]UPDATE TOTAL TRIGGER [b] [c]UPDATE TIME TRIGGER T-SQL FEATURES 1. Trigger 2. Stored procedure 3. Function TEST STRATEGY 1. 2. 3. QUERIES Member 1: X X X X X X X X X X X X X X X X X X X Sashi TP014682 Fadhil TP026366 X

A d v a n c e d D a t a b a s e | 29

Member 2: Member 3: PERSONAL REFLECTION REFERENCES X X

X X X X X X

References 1. Connolly T, & Begg, C., (2010). Database Systems: A Practical Approach to Design, Implementation, and Management (5th Edition). Boston: Pearson Education. Inc 2. Elmasri, R., & Navathe S.B., (2011). Database Systems: Models, Languages, Design and Application Programming (6th Edition).Boston: Pearson Education, Inc 3. Karwin, B., (2010). SQL Antipatterns: Avoiding the pitfalls of Database Programming: United States of America: Pragmatic Programmers, LLC 4. Kifer, M., Bernstein, A., & Lewis, P.M., (2006). Database Systems: AN application-oriented approach (2nd Edition). United States of America: Pearson Education, Inc. 5. Sanders, G.L., & Seungkyoon. S., (2001). Denormalization Effects on Performance of RDBMS. Proceedings of the 34th Hawaii International Conference on System Sciences, pp.1-9 6. Silberschatz A., Korth, H.F., & Sudarshan, S., (2011). Database System Concepts (6th edition) International Edition. Singapore: Mc-Graw Hill 7. Teamwork Theory [online]. (2007). Available from: <http://www.the-happymanager.com/articles/teamwork-theory/>. 8. [Accessed 13 December 2012].

9. Dirolf, M., (2010). Indexing [online] available from: http://www.dirolf.com [Accessed 15 May 2012] 10. J, Singh., (2011). Database Index Structures [online] available from:

http://www.slideshare.net/j_singh/database-index-structures [Accessed 15 Dec 2012] 11. Karwin, B., (2010). Mentor Your Indexes [online] available from:

http://www.slideshare.net/billkarwin/mentor-your-indexes [Accessed 15 Dec 2012] 12. Land Info Worldwide Mapping, LLC. (2012). Gis Definitions [online] available from: http://landinfo.com/resources_dictionaryAD.htm [Accessed 16 Dec 2012]

A d v a n c e d D a t a b a s e | 30

Appendix drop table Destination; drop table Passenger; drop table Reservation; drop table "DestinationSchedule"; drop table Payment; drop table Airline; drop table "PaymentAirline" drop table "Service" drop table Plane drop table Flight drop table Baggage drop table Meal drop table "FlightMeal"

create table Baggage ( Bag_ID int primary key IDENTITY(1,1), Bag_Description varchar(100) not null, Bag_Weight int not null, Bag_Remark varchar(100), F_Code int FOREIGN KEY REFERENCES Flight(F_Code) not null );

create table Meal ( M_ID int primary key IDENTITY(1,1), M_Name varchar(50), M_Type varchar(50), M_Description varchar(100) );

create table "FlightMeal"

A d v a n c e d D a t a b a s e | 31

( F_Code int FOREIGN KEY REFERENCES Flight(F_Code) not null, M_ID int FOREIGN KEY REFERENCES Meal(M_ID) not null )

create table Flight ( F_Code int primary key IDENTITY(1,1), F_Duration int not null, F_DepartLoc varchar(90) not null, F_DepartTime datetime not null, F_ArriveLoc varchar(90) not null, F_ArriveTime datetime not null, Plane_ID int FOREIGN KEY REFERENCES Plane(Plane_ID) not null, Sv_ID int FOREIGN KEY REFERENCES "Service"(Sv_ID) not null );

create table "Service" ( Sv_ID int primary key IDENTITY(1,1), Sv_Name varchar(30) not null, Sv_Type varchar(30) not null, Sv_Remark varchar(100), A_ID int FOREIGN KEY REFERENCES Airline(A_ID) not null )

create table Plane ( Plane_ID int primary key IDENTITY(1,1), Plane_Name varchar(30) not null, Plane_Capacity int not null, Plane_Remark varchar(100), A_ID int FOREIGN KEY REFERENCES Airline(A_ID) not null

A d v a n c e d D a t a b a s e | 32

);

create table "PaymentAirline" ( PA_ID int primary key IDENTITY(1,1), Delivered varchar(30) not null, Total int not null, Pay_ID int FOREIGN KEY REFERENCES Payment(Pay_ID) not null, A_ID int FOREIGN KEY REFERENCES Airline(A_ID) not null );

create table Airline ( A_ID int primary key IDENTITY(1,1), A_Name varchar(50) not null, A_Contact varchar(50) not null, A_Description varchar(100) not null, A_Email varchar(50) not null, A_Address varchar(100) not null );

create table Payment ( Pay_ID int primary key IDENTITY(1,1), Pay_Type varchar(50) not null, Pay_Amount int not null, "Date" datetime not null, P_ID int FOREIGN KEY REFERENCES Passenger(P_ID)not null );

create table "DestinationSchedule" ( DS_ID int primary key IDENTITY(1,1),

A d v a n c e d D a t a b a s e | 33

DepartDate datetime not null, Duration int not null, ArrivedDate datetime not null, D_ID int FOREIGN KEY REFERENCES Destination(D_ID) not null );

create table Reservation ( R_CODE int primary key IDENTITY (1,1), R_Quatity int not null, "Date" datetime not null, R_Option varchar(50), R_class varchar(50), R_Remark varchar(100), F_Code int FOREIGN KEY REFERENCES Flight(F_Code) not null, P_ID int FOREIGN KEY REFERENCES Passenger(P_ID) not null, DS_ID int FOREIGN KEY REFERENCES "DestinationSchedule"(DS_ID) not null, Pay_ID int FOREIGN KEY REFERENCES Payment(Pay_ID) not null ); create table Destination ( D_ID int primary key IDENTITY (1, 1), D_Name varchar(50) not null, D_Description varchar(100) not null, D_Remark varchar(50), ); create table Passenger ( P_ID int primary key IDENTITY (1,1), P_Name varchar(50) not null, P_IC varchar(19) not null, P_Phone varchar (30) not null,

A d v a n c e d D a t a b a s e | 34

P_Email varchar(50) not null , P_Birthday datetime not null, P_Gender char not null, DateJoin datetime not null, P_Status varchar(20) not null, P_Passport varchar(30) not null, P_Address varchar(100) not null, P_Country varchar(60) not null, Category varchar(40), Job varchar(80), Company varchar(70) , Remark varchar(100), "Type" varchar(50), );

CREATE INDEX IPassport ON Passenger (P_Passport)

DROP TRIGGER update_total GO CREATE TRIGGER update_total ON Payment AFTER INSERT,UPDATE AS IF UPDATE (Pay_Amount) BEGIN DECLARE @Pay_ID INT DECLARE @old_Pay_Amount INT DECLARE @new_Pay_Amount INT

SELECT @old_Pay_Amount = (SELECT Pay_Amount FROM deleted) SELECT @new_Pay_Amount = (SELECT Pay_Amount FROM inserted) SELECT @Pay_ID = (SELECT Pay_ID FROM inserted)

A d v a n c e d D a t a b a s e | 35

UPDATE "PaymentAirline" SET Total = Total + @new_Pay_Amount - @old_Pay_Amount FROM inserted AS I JOIN "PaymentAirline" AS U ON U.Pay_ID = I.Pay_ID END;

DROP TRIGGER update_Time GO CREATE TRIGGER update_Time ON Flight AFTER UPDATE AS IF UPDATE (F_ArriveTime) BEGIN UPDATE Reservation SET R_Remark = 'Delayed' FROM inserted AS I JOIN Reservation AS U ON U.F_Code = I.F_code END;

/*Functions*/ DROP FUNCTION TraceRecords GO CREATE FUNCTION TraceRecords ( @Name varchar(50) ) RETURNS @CustomerRecord table ( P_ID int, P_Name varchar(50), P_IC varchar(19), P_Passport varchar(30), P_Phone varchar(30), R_Class varchar(50), D_Name varchar(50), Pay_Type varchar(50), P_Amount int, PA_ID int, A_ID int, A_Name varchar(50) )

A d v a n c e d D a t a b a s e | 36

AS BEGIN INSERT INTO @CustomerRecord SELECT P_ID = P.P_ID, P_Name, P_IC, P_Passport, P_Phone, R_Class, D_Name, Pay_Type, Pay_Amount, PA_ID, A_ID = Air.A_ID, A_Name FROM [Airline].[dbo].[Passenger] AS P INNER JOIN [Airline].[dbo].[Reservation] AS R ON P.[P_ID]= R.[P_ID] INNER JOIN [Airline].[dbo].[DestinationSchedule] AS DS ON R.DS_ID = DS.DS_ID INNER JOIN [Airline].[dbo].[Destination] AS D ON DS.D_ID = D.D_ID INNER JOIN [Airline].[dbo].[Payment] AS Pay ON P.[P_ID] = Pay.[P_ID] INNER JOIN [Airline].[dbo].[PaymentAirline] AS PA ON Pay.[Pay_ID] = PA.[Pay_ID] INNER JOIN [Airline].[dbo].[Airline] AS Air ON PA.[A_ID] = Air.[A_ID] WHERE P_Name = @Name

RETURN END

Potrebbero piacerti anche