This set of Database Multiple Choice Questions & Answers (MCQs) focuses on “Modification of Database”.
1. A Delete command operates on ______ relation.
Explanation: Delete can delete from only one table at a time.
2. Delete from r where P;
The above command
a) Deletes a particular tuple from the relation
b) Deletes the relation
c) Clears all entries from the relation
d) All of the mentioned
Explanation: Here P gives the condition for deleting specific rows.
3. Which one of the following deletes all the entries but keeps the structure of the relation .
a) Delete from r where P;
b) Delete from instructor where dept name= ’Finance’;
c) Delete from instructor where salary between 13000 and 15000;
d) Delete from instructor;
Explanation: Absence of condition deletes all rows.
4. Which of the following is used to insert a tuple from another relation.
a) INSERT INTO course (course id, title, dept name, credits) VALUES (’CS-437’, ’DATABASE Systems’, ’Comp. Sci.’, 4); b) INSERT INTO instructor SELECT ID, name, dept name, 18000 FROM student WHERE dept name = ’Music’ AND tot cred > 144; c) INSERT INTO course VALUES (’CS-437’, ’DATABASE Systems’, ’Comp. Sci.’, 4); d) NOT possible
Explanation: Using select statement in insert will include rows which are the result of the selection.
5. Which of the following deletes all tuples in the instructor relation for those instructors associated with a department located in the Watson building which is in department relation.
a) DELETE FROM instructor WHERE dept_name IN 'Watson'; b) DELETE FROM department WHERE building='Watson'; c) DELETE FROM instructor WHERE dept_name IN (SELECT dept name FROM department WHERE building = ’Watson’); d) NONE OF the mentioned
Explanation: The query must include building=watson condition to filter the tuples.
UPDATE instructor _____ salary= salary * 1.05;
Fill in with correct keyword to update the instructor relation.
Explanation: Set is used to update the particular value.
7. _________ are useful in SQL update statements,where they can be used in the set clause.
a) Multiple queries
b) Sub queries
d) Scalar subqueries
8. The problem of ordering the update in multiple update is avoided using
Explanation: The case statements can add the order of updating tuples.
9. Which of the following is the correct format for case statements.
a) CASE WHEN pred1 ... result1 WHEN pred2 ... result2 . . . WHEN predn ... resultn ELSE result0 END b) CASE WHEN pred1 THEN result1 WHEN pred2 THEN result2 . . . WHEN predn THEN resultn ELSE result0 END c) CASE WHEN pred1 THEN result1 WHEN pred2 THEN result2 . . . WHEN predn THEN resultn ELSE result0 d) ALL OF the mentioned
10. Which of the following relation updates all instructors with salary over $100,000 receive a 3 percent raise, whereas all others receive a 5 percent raise.
a) UPDATE instructor SET salary = salary * 1.03 WHERE salary > 100000; UPDATE instructor SET salary = salary * 1.05 WHERE salary <= 100000; b) UPDATE instructor SET salary = salary * 1.05 WHERE salary < (SELECT avg (salary) FROM instructor); c) UPDATE instructor SET salary = CASE WHEN salary <= 100000 THEN salary * 1.05 ELSE salary * 1.03 END d) BOTH a AND c
Explanation: The order of the two update statements is important. If we changed the order of the two statements, an instructor with a salary just under $100,000 would receive an over 8 percent raise. SQL provides a case construct that we can use to perform both the updates with a single update statement, avoiding the problem with the order of updates.
Sanfoundry Global Education & Learning Series – Database Management System.