Shantanu Oak ([info]shantanuo) wrote,
@ 2009-06-13 17:07:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Current mood: happy
Entry tags:sqlite

SQLite Triggers
Assuming that customer records are stored in the "customers" table, and that order records are stored in the "orders" table, the following trigger ensures that all associated orders are redirected when a customer changes his or her address:

CREATE TRIGGER update_customer_address UPDATE OF address ON customers
BEGIN
UPDATE orders SET address = new.address WHERE customer_name = old.name;
END;

With this trigger installed, executing the statement:

UPDATE customers SET address = '1 Main St.' WHERE name = 'Jack Jones';

causes the following to be automatically executed:

UPDATE orders SET address = '1 Main St.' WHERE customer_name = 'Jack Jones';




Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…