Guest_imported
New member
- Jan 1, 1970
- 0
I have a problem deleting rows from multiple tables. I have 3 tables, tab1, tab2 and tab3. The tables are related, tab2 is foreignkey to primarykey in tab1. Tab2 is foriegnkey to tab3. (I try to visualise this below):
Tab3 <-- Tab2 --> Tab1
So, what I need to do is, delete all rows from the 3 tables that have a certain ID.
I need to send a parameter, for example 192 to a stored procedure, then this stored procedure should delete first the row in tab2 that has the ID 192, then it should delete the row in tab1 that has the ID 192 and finally delete the row from tab3 that has the ID 192. (I think it has to be done in that way, cause I cannot delete from tab1 first for example because it is primarykey to tab2).
It doesn't work for me like I've done the query, I get incorrect syntax error message:
CREATE PROCEDURE DeleteTest @arg INT AS
DELETE FROM tab1,tab2,tab3
WHERE tab2.[id]=@arg and tab1.[id]=@arg and tab3.[id]=@arg;
Hope someone can help me with this.
Thanks a lot!!
//Bob
Tab3 <-- Tab2 --> Tab1
So, what I need to do is, delete all rows from the 3 tables that have a certain ID.
I need to send a parameter, for example 192 to a stored procedure, then this stored procedure should delete first the row in tab2 that has the ID 192, then it should delete the row in tab1 that has the ID 192 and finally delete the row from tab3 that has the ID 192. (I think it has to be done in that way, cause I cannot delete from tab1 first for example because it is primarykey to tab2).
It doesn't work for me like I've done the query, I get incorrect syntax error message:
CREATE PROCEDURE DeleteTest @arg INT AS
DELETE FROM tab1,tab2,tab3
WHERE tab2.[id]=@arg and tab1.[id]=@arg and tab3.[id]=@arg;
Hope someone can help me with this.
Thanks a lot!!
//Bob