how we can delete record of a table when record of another table deleted using function,trigger in postgresql -concepts
views:
26answers:
2
A:
add a foreign key constraint then use a cascading delete (assuming this exists in postgresql, I don't know)
lexu
2010-02-04 05:09:38
+1
A:
Use "ON DELETE CASCADE" on the column definition. Something like this will do what you want:
CREATE TABLE shopping_carts (
id SERIAL PRIMARY KEY
,cart_name varchar NOT NULL
);
CREATE TABLE cart_items (
id SERIAL PRIMARY KEY
,cart_id INT REFERENCES shopping_carts(id) ON DELETE CASCADE
,item_description varchar NOT NULL);
jamieb
2010-02-04 05:17:02