I have two tables:
Requests – Request_id , Request_Message; // contains Requests
Responses – Response_id , Request_id , Response_Message; // Contains Responses for the request..
Request_id is foreign key for this table
Now while i am running the query delete from requests where Request_id = “REQ001”;.... if there is no corresponding response in responses table then query is working fine, other its giving foreign key constraint error.
I want while i delete any request from requests table all its corresponding responses must delete automatically from response table.. How to achieve this??
Thanks for your time..
Devesh
Using
CASCADEin the definition of theFOREIGN KEYconstraint is an option. However, I recommend using the multiple-table syntax of the delete statement, e.g.:This is my preferred solution because it makes more explicit what actually happens.