Textbook: Digital Systems Chapter 8  Question/Problem 44 I'm not sure if I'm running the correct Query for this problem.  The question is: "Create a trigger named trg_char_hours that automatically updates 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. (Hint: use temp values, as the INSERT event does not accept the OLD keyword.)"   I ran this query without any errors:  CREATE TRIGGER trg_char_hours AFTER INSERT ON CHARTER FOR EACH ROW UPDATE AIRCRAFT SET AC_TTAF = AC_TTAF + NEW.CHAR_HOURS_FLOWN, AC_TTEL = AC_TTEL + NEW.CHAR_HOURS_FLOWN, AC_TTER = AC_TTER + NEW.CHAR_HOURS_FLOWN WHERE AIRCRAFT.AC_NUMBER = NEW.AC_NUMBER;   But the answer is still incorrect because the last row doesn't have the expected values. I'm not sure why the test query would delete any row with a CHAR_TRIP ABOVE 10018. I attached a scree

Database Systems: Design, Implementation, & Management
12th Edition
ISBN:9781305627482
Author:Carlos Coronel, Steven Morris
Publisher:Carlos Coronel, Steven Morris
Chapter7: Introduction To Structured Query Language (sql)
Section: Chapter Questions
Problem 13P: Write the two SQL command sequences required to: a.Create a temporary table named TEMP_1 whose...
icon
Related questions
icon
Concept explainers
Question

Textbook: Digital Systems

Chapter 8 

Question/Problem 44

I'm not sure if I'm running the correct Query for this problem. 

The question is:

"Create a trigger named trg_char_hours that automatically updates 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.

(Hint: use temp values, as the INSERT event does not accept the OLD keyword.)"

 

I ran this query without any errors: 

CREATE TRIGGER trg_char_hours
AFTER INSERT ON CHARTER
FOR EACH ROW
UPDATE AIRCRAFT
SET AC_TTAF = AC_TTAF + NEW.CHAR_HOURS_FLOWN,
AC_TTEL = AC_TTEL + NEW.CHAR_HOURS_FLOWN,
AC_TTER = AC_TTER + NEW.CHAR_HOURS_FLOWN
WHERE AIRCRAFT.AC_NUMBER = NEW.AC_NUMBER;
 
But the answer is still incorrect because the last row doesn't have the expected values. I'm not sure why the test query would delete any row with a CHAR_TRIP ABOVE 10018. I attached a screen of the output I'm getting:
 
Problems 8.44-8.46
query.sql
+
Some expected rows were missing (shown in red below).
55
56
Some unexpected rows were returned.
57 CREATE TRIGGER trg_char_hours
58 AFTER INSERT ON CHARTER
Test Query ®
59 FOR EACH ROW
60 UPDATE AIRCRAFT
UPDATE AIRCRAFT SET AC_TTAF = 1833.1, AC_TTEL = 1833.1, AC_TTER = 101.8 WHERE AC_NUMBER =
INSERT INTO CHARTER VALUES('10019','2018 -02-10','1484P','TYS','644','10','4.5','167.4','0'
61 SET AC_TTAF = AC_TTAF + NEW.CHAR_HOURS_FLOWN,
62 AC TTEL = AC TTEL + NEW.CHAR HOURS FLOWN,
SELECT * FROM AIRCRAFT
63 AC TTER = AC TTER + NEW.CHAR HOURS FLOWN
DELETE FROM CHARTER WHERE CHAR TRIP > 10018
64 WHERE AIRCRAFT.AC NUMBER = NEW.AC NUMBER;
UPDATE AIRCRAFT SET AC_TTAF = 1833.1, AC_TTEL = 1833.1, AC_TTER = 101.8 WHERE AC_NUMBER =
65 */
66
67 select * from CHARTER WHERE AC_NUMBER = '4278Y' order by CHAR_DATE;
Expected Results ®
AC NUMBER
MOD_CODE
AC_TTAF
AC TTEL
AC_TTER
9 SQL Viewer
+
1484P
PA23-250
1843.1
1843.1
111.8
CHAR_TRIP
CHAR DATE AC NUMBER
CHAR_DESTINATION CHAR_DISTANCE CHAR_HOURS_FLOWN
CHAR_HOURS_WAIT
CHAR_FUEL_
2289L
C-90A
4243.8
768.9
1123.4
2018-02-05
2778V
РАЗ1-350
7992.9
1513.1
789.5
10003
4278Y
GNV
1574
7.8
339.8
00:00:00
4278Y
РАЗ1-350
2147.3
622.1
243.2
2018-02-06
10006
4278Y
STL
472
2.6
5.2
117.1
00:00:00
Actual Results e
2018-02-07
10010
4278Y
ATL
998
6.2
3.2
279.7
AC_NUMBER
MOD CODE
AС TTAF
AC_TTEL
AC TTER
00:00:00
1484P
PA23-250
1843.1
1843.1
111.8
2018-02-08
10013
4278Y
TYS
644
3.9
4.5
174.3
00:00:00
2289L
C-90A
4243.8
768.9
1123.4
2018-02-09
10014
4278Y
ATL
936
6.1
2.1
302.6
2778V
РАЗ1-350
7992.9
1513.1
789.5
00:00:00
4278Y
РАЗ1-350
2151.1
625.9
247
2018-02-10
10018
4278Y
TYS
644
3.8
4.5
167.4
00:00:00
2018-02-10
NULL
4278Y
TYS
644
3.8
4.5
167.4
00:00:00
Transcribed Image Text:Problems 8.44-8.46 query.sql + Some expected rows were missing (shown in red below). 55 56 Some unexpected rows were returned. 57 CREATE TRIGGER trg_char_hours 58 AFTER INSERT ON CHARTER Test Query ® 59 FOR EACH ROW 60 UPDATE AIRCRAFT UPDATE AIRCRAFT SET AC_TTAF = 1833.1, AC_TTEL = 1833.1, AC_TTER = 101.8 WHERE AC_NUMBER = INSERT INTO CHARTER VALUES('10019','2018 -02-10','1484P','TYS','644','10','4.5','167.4','0' 61 SET AC_TTAF = AC_TTAF + NEW.CHAR_HOURS_FLOWN, 62 AC TTEL = AC TTEL + NEW.CHAR HOURS FLOWN, SELECT * FROM AIRCRAFT 63 AC TTER = AC TTER + NEW.CHAR HOURS FLOWN DELETE FROM CHARTER WHERE CHAR TRIP > 10018 64 WHERE AIRCRAFT.AC NUMBER = NEW.AC NUMBER; UPDATE AIRCRAFT SET AC_TTAF = 1833.1, AC_TTEL = 1833.1, AC_TTER = 101.8 WHERE AC_NUMBER = 65 */ 66 67 select * from CHARTER WHERE AC_NUMBER = '4278Y' order by CHAR_DATE; Expected Results ® AC NUMBER MOD_CODE AC_TTAF AC TTEL AC_TTER 9 SQL Viewer + 1484P PA23-250 1843.1 1843.1 111.8 CHAR_TRIP CHAR DATE AC NUMBER CHAR_DESTINATION CHAR_DISTANCE CHAR_HOURS_FLOWN CHAR_HOURS_WAIT CHAR_FUEL_ 2289L C-90A 4243.8 768.9 1123.4 2018-02-05 2778V РАЗ1-350 7992.9 1513.1 789.5 10003 4278Y GNV 1574 7.8 339.8 00:00:00 4278Y РАЗ1-350 2147.3 622.1 243.2 2018-02-06 10006 4278Y STL 472 2.6 5.2 117.1 00:00:00 Actual Results e 2018-02-07 10010 4278Y ATL 998 6.2 3.2 279.7 AC_NUMBER MOD CODE AС TTAF AC_TTEL AC TTER 00:00:00 1484P PA23-250 1843.1 1843.1 111.8 2018-02-08 10013 4278Y TYS 644 3.9 4.5 174.3 00:00:00 2289L C-90A 4243.8 768.9 1123.4 2018-02-09 10014 4278Y ATL 936 6.1 2.1 302.6 2778V РАЗ1-350 7992.9 1513.1 789.5 00:00:00 4278Y РАЗ1-350 2151.1 625.9 247 2018-02-10 10018 4278Y TYS 644 3.8 4.5 167.4 00:00:00 2018-02-10 NULL 4278Y TYS 644 3.8 4.5 167.4 00:00:00
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Query Syntax
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781305627482
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781285196145
Author:
Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos Coronel
Publisher:
Cengage Learning