Test the Trigger
In this step, you will test the behavior of the trigger. You'll insert data into the employees
table and then update the salary to see if the trigger correctly logs the changes in the salary_changes
table.
First, insert some initial data into the employees
table:
INSERT INTO employees (name, salary) VALUES ('Alice', 50000.00);
INSERT INTO employees (name, salary) VALUES ('Bob', 60000.00);
Now, update Alice's salary:
UPDATE employees SET salary = 55000.00 WHERE name = 'Alice';
To verify that the trigger worked correctly, query the salary_changes
table:
SELECT * FROM salary_changes;
You should see a row in the salary_changes
table with the information about Alice's salary change.
Next, update Bob's salary to the same value it already has:
UPDATE employees SET salary = 60000.00 WHERE name = 'Bob';
Since the salary is not actually changing, the trigger should not insert a new row into the salary_changes
table. Let's verify this:
SELECT * FROM salary_changes;
You should still only see the one row related to Alice's salary change.
Finally, insert a new employee:
INSERT INTO employees (name, salary) VALUES ('Charlie', 70000.00);
Inserting a new employee should not trigger the log_salary_change
trigger, as it's only set to fire on UPDATE
events. Let's confirm this by checking the salary_changes
table again:
SELECT * FROM salary_changes;
You should still only see the one row related to Alice's salary change.