THANKS SO MUCH CHEGG! This ones a bit long! I apologize! Suppose we have the fol
ID: 3723987 • Letter: T
Question
THANKS SO MUCH CHEGG! This ones a bit long! I apologize!
Suppose we have the following:
CREATE TABLE Beers ( name origin CHAR(20) PRIMARY KEY, CHAR (120) CREATE TABLE Sells ( bar CHAR(20), beer CHAR(20), price REAL, FOREIGN KEY(beer) REFERENCES Beers(name) ON DELETE SET NULL, ON UPDATE CASCADE Assume the following data already exists in our database Beers Table Sells Table Origin Name B1 B2 B3 Bar Beer Price Bar B1 Bar B1 Bar B2 Bar2 B3 Bar2 B3 Bar3 B1 2 02 03 4 4 We execute the following two queries DELETE FROM Beers where name 'B1' UPDATE Beers set Name 'B4' Where Name-'B3'; Now, what does this query return? SELECT SUM(Price) FROM Sells WHERE Sells.Beer IS NOT NULL; b) 10 c) 13 d) 20Explanation / Answer
Ans. Option (c)
Explanation: On deletion from the parent table, the name in sells table will be set to NULL and since Cascade is used with the update so when we update parent table Beer the names will be updated in Sells table also. Now when the query runs it sums up all the price except those of NULL so total will come as 3+4+6 = 13
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.