Triggers question
Posted in 2000
Topics: Triggers, Constraints & Referential Integrity
I'm trying to use a combination of triggers and foreign key constraints to enforce referential integrity on a database. An example: table customers: cust_num primary key table calls: call_id primary key, cust_num foreign key referencing customers.cust_num This foreign key constraint prevents inserting a calls row without a valid cust_num. Then, I have triggers on the customers table to cascade deletes and updates of cust_num to the calls table, so if a user deletes a customer, the calls rows for that customer are also deleted; if a user updates customer.cust_num, the new value is applied to the calls.cust_num values for that customer. This doesn't work (the error "key value for constraint is still being referenced" occurs on delete/update of customer), which makes sense, but I was curious if there is any way to do this at the database level.
Nevermind. I was trying this on an SE database. Per RTFM, SE constraint checking occurs prior to the triggered action and causes this problem, even with transaction logging.