Database triggers are only executed by the database engine when DML statements (insert, update, delete) are executed against the table.
CREATE TRIGGER tr_manager
BEFORE UPDATE OF dept_head_id
ON department
REFERENCING OLD AS old_dept NEW AS new_dept
FOR EACH ROW
BEGIN
UPDATE employee
SET employee.manager_id=new_dept.dept_head_id
WHERE employee.dept_id=old_dept.dept_id
END
For example, this trigger code will only be executed if I issue an update statement against the department table that changes the dept_head_id column:
"UPDATE OF dept_head_id ON department"
HTH,
Dave
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Dave has already answered your question, but I just thought I'll make it more explicit.
You can test the effects of a trigger by running the SQL that is designed to trigger it and checking for the side effects, so this would be two (or more) tests in SQLUnit. SQLUnit fires the tests in the order you specify them so you are ok there.
So yes, its possible to use SQLUnit to test your triggers, although not in a single test. Your first test will invoke the trigger indirectly by invoking the SQL that is supposed to trigger the trigger, and your second (and subsequent) test(s) will look at the other tables the trigger was supposed to touch and verify that it did its thing correctly.
-sujit
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Sujit
Is there any to test the triggers using the SQLUnit ?
Thanks
Meghanath
Database triggers are only executed by the database engine when DML statements (insert, update, delete) are executed against the table.
CREATE TRIGGER tr_manager
BEFORE UPDATE OF dept_head_id
ON department
REFERENCING OLD AS old_dept NEW AS new_dept
FOR EACH ROW
BEGIN
UPDATE employee
SET employee.manager_id=new_dept.dept_head_id
WHERE employee.dept_id=old_dept.dept_id
END
For example, this trigger code will only be executed if I issue an update statement against the department table that changes the dept_head_id column:
"UPDATE OF dept_head_id ON department"
HTH,
Dave
Hi Meghanath,
Dave has already answered your question, but I just thought I'll make it more explicit.
You can test the effects of a trigger by running the SQL that is designed to trigger it and checking for the side effects, so this would be two (or more) tests in SQLUnit. SQLUnit fires the tests in the order you specify them so you are ok there.
So yes, its possible to use SQLUnit to test your triggers, although not in a single test. Your first test will invoke the trigger indirectly by invoking the SQL that is supposed to trigger the trigger, and your second (and subsequent) test(s) will look at the other tables the trigger was supposed to touch and verify that it did its thing correctly.
-sujit