views:

26

answers:

2

how we can delete record of a table when record of another table deleted using function,trigger in postgresql -concepts

A: 

add a foreign key constraint then use a cascading delete (assuming this exists in postgresql, I don't know)

lexu
+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