MySQL Database Multiple Choice Questions on “Triggers”.
1. Triggers enable to enforce data integrity constraints.
a) True
b) False
Answer: a
Clarification: In MySQL, a trigger can examine or change new data values to be inserted or used to update a row in a table. This enables the enforcement of the data integrity constraints.
2. Which statement is used to create a trigger?
a) CREATE TRIGGER
b) CREATE TRIGGERS
c) PRODUCE TRIGGER
d) PRODUCE TRIGGERS
Answer: a
Clarification: In order to create a trigger, the CREATE TRIGGER statement is used. The definition indicates the particular type of statement for which the trigger activates and whether it activates before or after the rows are modified.
3. For which of the following are triggers not supported?
a) delete
b) update
c) insert
d) views
Answer: d
Clarification: In MySQL, the triggers are run only after the table modifications like insert, update and delete are run. Triggers are not supported for views. In order to create a trigger, the CREATE TRIGGER statement is used.
4. Which statement is used to remove a trigger?
a) REMOVE
b) DELETE
c) DROP
d) CLEAR
Answer: c
Clarification: In order to delete a trigger, the DROP TRIGGER statement is used. The DROP TRIGGER construct is used by writing the phrase ‘DROP TRIGGER’ followed by the scheme name specification.
5. Before MySQL 5.1.6 which privilege was required to create and drop triggers?
a) PRIVILEGE
b) TRIGGER
c) SUPER
d) MACRO
Answer: c
Clarification: The privilege to create and drop triggers is version specific in MySQL. Before MySQL 5.1.6, the SUPER privilege was needed. Access control is more correctly handled post this version.
6. The TRIGGER privilege is used for the table to be able to create and drop triggers for it.
a) True
b) False
Answer: a
Clarification: In MySQL, because a trigger is associated with a table, the TRIGGER privilege is a must for that table to be able to create and drop triggers for it. The SUPER privilege was used pre 5.1.6.
7. What is abc in the following MySQL statement?
CREATE TRIGGER abc (...) (...) ON def FOR EACH ROW ghi;
a) trigger name
b) table name
c) trigger statement
d) update statement
Answer: a
Clarification: In MySQL, the trigger creation construct is the ‘CREATE TRIGGER’ construct. It specifies the trigger name, the type of statement for which it is activated, and the table name and statement.
8. What is def in the following MySQL statement?
CREATE TRIGGER abc (...) (...) ON def FOR EACH ROW ghi;
a) trigger name
b) table name
c) trigger statement
d) update statement
Answer: b
Clarification: The trigger creation construct in MySQL is the ‘CREATE TRIGGER’ construct. It specifies components like the trigger name, the type of statement for which it is activated, and the table name and statement.
9. What is ghi in the following MySQL statement?
CREATE TRIGGER abc (...) (...) ON def FOR EACH ROW ghi;
a) trigger name
b) table name
c) trigger statement
d) update statement
Answer: c
Clarification: In MySQL, the trigger creation construct is the ‘CREATE TRIGGER’ construct. It specifies components like the trigger name, the type of statement for which it is activated, and the table name and statement.
10. What is def in the following MySQL statement?
DECLARE abc HANDLER FOR def ghi;
a) action
b) condition value
c) statement
d) null
Answer: b
Clarification: The ‘DECLARE HANDLER’ statement is used to declare a handler. When a condition whose value matches def, MySQL will execute ghi and either continue or exit the current code block.
