Q1
True / Falsetrigger in MySQL can be created to automatically update a table before an INSERT operation is performed.
MySQL triggers can be set to activate before or after INSERT, UPDATE, or DELETE operations. A trigger can perform actions before the specified operation is executed.
Q2
True / FalseYou can only have one trigger for each type of operation (before/after insert/update/delete) on a single table in MySQL.
MySQL allows multiple triggers of the same type (e.g., multiple BEFORE INSERT triggers) on a single table, as long as they have unique names.
Q3
True / FalseTriggers in MySQL can be used to enforce data integrity by validating data before it is committed to the database.
Triggers can be used to validate data and ensure it meets certain criteria before changes are applied to the database, thus helping enforce data integrity.
Q4
True / FalseTriggers in MySQL can directly call other triggers.
MySQL does not support direct triggering of other triggers. However, actions within a trigger can lead to changes that might activate other triggers if they are set on the same table.
Q5
True / FalseMySQL, a BEFORE UPDATE trigger can modify the values of the row being updated.
BEFORE UPDATE trigger can modify the values of the row being updated before the update operation is completed.
Q6
True / FalseTriggers in MySQL can be used to automatically log changes made to a table by inserting records into an audit table.
Triggers can be designed to log changes to an audit table, capturing details of operations performed on the original table.
Q7
True / FalseMySQL triggers can only be used to manipulate data within the same table where the trigger is defined.
Triggers can manipulate data in other tables as well, not just the table where the trigger is defined, though this should be done carefully to avoid unintended consequences.
Q8
True / FalseMySQL, you can create triggers that run after an INSERT operation on a view.
Triggers in MySQL can only be created for tables, not for views.
Q9
True / FalseThe OLD and NEW keywords in MySQL triggers refer to the values of the rows before and after an UPDATE operation, respectively
In a trigger, OLD refers to the rowβs values before the change, and NEW refers to the rowβs values after the change, particularly in UPDATE triggers.
Q10
True / FalseMySQL, a trigger created with the BEFORE DELETE timing cannot prevent the deletion of rows from a table.
BEFORE DELETE trigger can indeed prevent the deletion of rows by raising an error or taking some other action to cancel the operation.
Q21
Multiple ChoiceIdentify the correct SQL statement to create a trigger that logs changes to a table after an update.
SQL Code
CREATE TRIGGER log_update
AFTER UPDATE ON employees
FOR EACH ROW
INSERT INTO employee_log (employee_id, old_salary, new_salary)
VALUES (OLD.employee_id, OLD.salary, NEW.salary);
This trigger captures changes made to the employees table and logs the old and new salary values in the employee_log table.
Q28
Multiple ChoiceIdentify the correct SQL statement to create a trigger that logs changes to multiple columns in a table.
SQL Code
CREATE TRIGGER log_changes
AFTER UPDATE ON inventory
FOR EACH ROW
BEGIN
IF OLD.price <> NEW.price THEN
INSERT INTO inventory_log (item_id, old_price, new_price)
VALUES (OLD.item_id, OLD.price, NEW.price);
END IF;
IF OLD.stock <> NEW.stock THEN
INSERT INTO inventory_log (item_id, old_stock, new_stock)
VALUES (OLD.item_id, OLD.stock, NEW.stock);
END IF;
END;
This AFTER UPDATE trigger logs changes to both the price and stock columns in the inventory table, capturing any modifications made.