Question 2: Triggers and Stored Procedures Download the file named “assignment5_database.sql” from D2L. Run the file from MySQL command window using the command (assuming the file is stored under c:\\): mysql> source c:\\assignment5_database.sql After the file completes, the tables shown above are created and populated with the shown data. Familiarize yourself with the database before starting to write your queries. Once you are familiar with the data, start working on the following questions. Answer the following questions based on the above database: Create a view named “Atlanta_Charter_Crew_V” that includes the following “For each charter of aircraft to Atlanta (ATL), print the charter date, charter distance, and the corresponding crew (employee) number, last name, first name, and crew job”. Your answer should include both the SQL statement for view creation along with the contents of the view (you get the contents of the view by running the command select * from Atlanta_Charter_Crew_V;). Modify the MODEL table to add the following attribute and insert the values shown in the following table. (Note: use ALTER TABLE and UPDATE commands.) Attribute name Attribute Description Attribute type Attribute Values MOD_TOTAL_ WEIGHT Weight of each model Numeric 12,500 for C-90A 7,300 for PA23-250 19,770 for PA31-350 Create a trigger named trg_charter_time that will automatically update the AIRCRAFT table when a new CHARTER row is added. Use the CHARTER table’s CHAR_HOURS_FLOWN to update the AIRCRAFT table’s AC_TTAF, AC_TTEL, and AC_TTER values. The meaning for the AIRCRAFT table columns are as follows: AC_TTAF: Total time on the air frame (before maintenance) AC_TTEL: Total time on the left engine (before maintenance, also track single engine) AC_TTER: Total time on the right engine (before maintenance) So in the trigger, you need to decrease all of them by the number of CHAR_HOUR_FLOWN Create a trigger named trg_cust_charge that will automatically update the CUSTOMER table’s CUS_BALANCE when a new CHARTER row is added. Use the CHARTER table’s CHAR_TOT_CHG as the update source (Assume that all charter charges are charged to the customer balance.) In addition to the CHAR_TOT_CHG, add a $5 service charge for every 50 miles flown. Create a stored procedure to update an Aircraft’s time till maintenance. Procedure takes the Aircraft number (ac_number) as a parameter. The procedure then resets the aircraft’s attributes: ac_ttaf to 5000, ac_ttel to 7775 and ac_tter to 8805 (right engines last longer, less stress on take offs). Create a stored procedure that will take a Pilot’s number and percentage, then update the corresponding pilot’s annual salary by the input percentage (increase the annual salary, so you are giving the pilot a raise). Hint: you may have to do some additional work (alter table) on this one to get the table correct.
Question 2: Triggers and Stored Procedures
Download the file named “assignment5_database.sql” from D2L. Run the file from MySQL command window using the command (assuming the file is stored under c:\\):
mysql> source c:\\assignment5_database.sql
After the file completes, the tables shown above are created and populated with the shown data. Familiarize yourself with the
Answer the following questions based on the above database:
- Create a view named “Atlanta_Charter_Crew_V” that includes the following “For each charter of aircraft to Atlanta (ATL), print the charter date, charter distance, and the corresponding crew (employee) number, last name, first name, and crew job”. Your answer should include both the SQL statement for view creation along with the contents of the view (you get the contents of the view by running the command select * from Atlanta_Charter_Crew_V;).
- Modify the MODEL table to add the following attribute and insert the values shown in the following table. (Note: use ALTER TABLE and UPDATE commands.)
Attribute name |
Attribute Description |
Attribute type |
Attribute Values |
MOD_TOTAL_ WEIGHT |
Weight of each model |
Numeric |
12,500 for C-90A 7,300 for PA23-250 19,770 for PA31-350 |
- Create a trigger named trg_charter_time that will automatically update the AIRCRAFT table when a new CHARTER row is added. Use the CHARTER table’s CHAR_HOURS_FLOWN to update the AIRCRAFT table’s AC_TTAF, AC_TTEL, and AC_TTER values. The meaning for the AIRCRAFT table columns are as follows: AC_TTAF: Total time on the air frame (before maintenance)
AC_TTEL: Total time on the left engine (before maintenance, also track single engine)
AC_TTER: Total time on the right engine (before maintenance)
So in the trigger, you need to decrease all of them by the number of CHAR_HOUR_FLOWN
- Create a trigger named trg_cust_charge that will automatically update the CUSTOMER table’s CUS_BALANCE when a new CHARTER row is added. Use the CHARTER table’s CHAR_TOT_CHG as the update source (Assume that all charter charges are charged to the customer balance.) In addition to the CHAR_TOT_CHG, add a $5 service charge for every 50 miles flown.
- Create a stored procedure to update an Aircraft’s time till maintenance. Procedure takes the Aircraft number (ac_number) as a parameter. The procedure then resets the aircraft’s attributes: ac_ttaf to 5000, ac_ttel to 7775 and ac_tter to 8805 (right engines last longer, less stress on take offs).
- Create a stored procedure that will take a Pilot’s number and percentage, then update the corresponding pilot’s annual salary by the input percentage (increase the annual salary, so you are giving the pilot a raise). Hint: you may have to do some additional work (alter table) on this one to get the table correct.
![Database name: Ch08_AviaCo
Table name: CHARTER
Table name: EARNEDRATING
CHAR TRIP CHAR DATE AC_NUMBER CHAR DESTINATION CHAR DISTANCE CHAR HOURS FLOWN CHAR HOURS WAIT CHAR FUEL GALLONS CHAR OL_QTS CUS CODE
10011
5.1
22
354,1
10016
10014
2.
10001 05-Feb-08 2289L
906
726
EMP NUM RTG CODE EARNRTG DATE
1.6
10002 05-Feb-08 2778V
BNA
7.8
86-99381
GNV
1574
15-Dec-05
08-Nov-93
10003 05-Feb-08 4278Y
972
101 CFI
472
6100
10004 06-Feb-08 1484P
STL
10011
10017
10012
101 NSTR
1023
5.7
35
ATL
23-Jun-94
21-Apr-93
10005 06-Feb-08 2289L
101 MEL
472
26
52
117.1
10006 06-Feb-08 4278Y
101 SEL
us
343.4
2
1574
10007 06-Feb-08 2778V
62
104 NSTR
ANO
10014
140.6
644
96 SI
SAI
GNV
29-Jan-97
10008 07-Feb-08 1484P
10017
104 MEL
66S
279.7
234
99
62
1574
104 SEL
12-Mar-95
9100
10012
768Z 00-9920 6000
32
טנר
BNA
866
352
18-Nov-97
17-Apr-95
12-Aug-95
23-Sep-94
20-Dec-95
10010 07-Feb-08 4278Y
53
664
10011 07-Feb-08 1484P
1.
42
215.1
10010
105 NSTR
10012 08-Feb-08 2778V
MOB
884
4.8
105 MEL
45
1743
10011
SAI
ATL
10013 08-Feb-08 4278Y
13S SOL
106 INSTR
6.1
2.1
10017
966
1645
10014 09-Feb-08 4278Y
6.7
459.5
10016
10015 09-Feb-08 2289L
02-Apr-96
10-Mar-94
2.
ANO
10011
10016 09-Feb-08 2778V
312
15
67 2
106 SEL
10014
10017
AOH
105.5
us
SAI
10017 10-Feb-08 1484P
3.1
05-Nov-98
805
167.4
10018 10-Feb-08 4278Y
3.8
45
LO 601
109 INSTR
Table name: CREW
Table name: CUSTOMER
96 T
15-Mar-97
109 MEL
CHAR TRIP EMP NUM CREW JOB
CUS CODE CUS LNAME CUS FNAME CUS NTIAL CUS AREACODE CUS_PHONE CUS BALANCE
109 SEL
05-Feb-96
104 Plot
844-2573
109 SES
12-May-96
LO00
10002
10010 Ramas
Alfred
A
615
000
000
896.54
101 Plot
10011 Dunne
713
894-1238
10003
105 Plot
10012 Smith
Kathy
615
894-2285
W.
Table name: RATING
109 Copilot
10013 Olowski
615
894-2180
1285.19
PO00
10005
106 Plot
673.21
1014.56
10014 Orlando
Myron
615
222-1672
RTG CODE
RTG NAME
101 Plot
10015 OBrian
713
442-3381
Certified Flight Instructor
109 Plot
9000
Jarmes
615
297-1228
000
Certified Flight Instructor, Instrument
104 Plot
UMOg 9100
290-2556
LO001
10017 Wiams
615
NSTR
Instrumert
2000
90001
105 Copilot
000
000
453.98
10018 Farriss
713
382-7185
Multiengine Land
Single Engine, Land
Single Engine, Sea
106 Plot
MEL
105 Plot
10019 Smith
Olette
615
6000
108 Plot
Table name: EMPLOYEE
SES
10011
101 Plot
10011
104 Copilat
EMP NUM EMP_ TITLE EMP LNAME EMP FNAME EMPNTIAL EMP DOB EMP HRE DATE
15-Mar-1987
25-Apr-1988 Table name: MODEL
20-Dec-1992
10012
101 Plot
100 Mr.
15-Jun-1942
10013
105 Plot
101 Ms.
Lewis
19-Mar-1965
10014
epuon
106 Plot
102 Mr,
Vandam
Rhett
14-Nov-1958
MOD CODE MOD MANUFACTURER
MOD NAME MOD SEATS MOD CHG_MILE
2.67
10015
101 Copilot
28-Aug-2005
20-Od-1996
08-Jan-2006 PA31-350 Piper
16-Oct-1974
sauor
C-90A
Beechcraft
10015
104 Piot
104 Mr.
John
08-Nov-1971
10016
105 Coplot
PA23-250 Piper
Aztec
D.
K
105 Mr.
Wiliams
Robert
14-Mar-1975
10016
Navajo Chiettain
235
Pid 601
106 Mrs.
Jeanine
12-Feb-1968
05-Jan-1991
10017
107 Mr.
Diante
21-Aug-1974
02--1996
104 Copilot
105 Plot
18-Nov-1994
14-Apr-1991
01-Dec-1992
108 Mr.
Wiesenbach Pad
14-Feb-1966
10018
R.
109 Ms.
Travis
Eizabeth
18-un-1961
110 Mrs.
Genkazi
19-May-1970
Table name: AIRCRAFT
Table name: PILOT
AC NUMBER MOD CODE AC TTAF AC TTEL AC_TTER
EMP NUM PIL LCENSE
PIL RATINGS
PL MED TYPE PL_MED_DATE PL PT135 DATE
1484P
PA23-250
1833.1
1833.1
101.8
101 ATP
ATP/SELMELinstriÇFI
11-Jan-08
17 Jan-08
02-Jan-08
02-Feb-08
20-Jan-08
1.
76827
2778V
689
1123.4
1513.1
C-90A
4243.8
104 ATP
ATP/SELMELinstr
1.
COMM/SELMELinstr/CFI
18-Dec-07
PA31-350
7992.9
789.5
105 COM
4278Y
PA31-350
80-us0
2147.3
622.1
243.2
106 COM
COMMISELMELAnstr
10-Dec-07
ATPISELMELISESAnstr/CFI 1
15-Jan-08
WOO 601
90-ue](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa01eac1b-e705-4f10-b34b-cee88a03092f%2F433f87e9-2795-4945-be85-aded06d39d02%2F6afaaxu.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781305627482/9781305627482_smallCoverImage.gif)
![Enhanced Discovering Computers 2017 (Shelly Cashm…](https://www.bartleby.com/isbn_cover_images/9781305657458/9781305657458_smallCoverImage.gif)
![Principles of Information Systems (MindTap Course…](https://www.bartleby.com/isbn_cover_images/9781285867168/9781285867168_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781305627482/9781305627482_smallCoverImage.gif)
![Enhanced Discovering Computers 2017 (Shelly Cashm…](https://www.bartleby.com/isbn_cover_images/9781305657458/9781305657458_smallCoverImage.gif)
![Principles of Information Systems (MindTap Course…](https://www.bartleby.com/isbn_cover_images/9781285867168/9781285867168_smallCoverImage.gif)
![Oracle 12c: SQL](https://www.bartleby.com/isbn_cover_images/9781305251038/9781305251038_smallCoverImage.gif)
![A Guide to SQL](https://www.bartleby.com/isbn_cover_images/9781111527273/9781111527273_smallCoverImage.gif)