I have a relational database. Pretty simple I created it just for learning from it.
I have two tables "Categories" and "Subcategories".
I have a field called "CategoryID" in the Subcategories table that is a foreign key , and is related to the first table (categories).
Now what I want to do is, when I delete a row in the "Categories" table, I also want to delete the related rows in the other table (if any exist) at the same time.
I hope I explained the problem accurately, if you need any details please let me know
Thanks in advace,
WassimHi,
You need to delete the rows from the subcategories table first and then delete the corresponding rows from the categories table.
It should be pretty easy as the CategoryID should be in SubCategories table and that the field you need to use to delete rows from the subcategories table.
I hope this helps.
Aash.|||Look at the CASCADE DELETE capability defined when you set the relationship between the two tables. This is inherent and designed to provide for integrity as part of the db structure
Jim|||
Quote:
Originally Posted by Jim Doherty
Look at the CASCADE DELETE capability defined when you set the relationship between the two tables. This is inherent and designed to provide for integrity as part of the db structure
Jim
Hi Jim,
yes that's what I did exactly. That's amazing. if you force your tables to "Cascade Delete", and you delete a row in a parent table, all the rows in the childs tables will also be removed :)
Thanks|||
Quote:
Originally Posted by Tea Maker
Hi Jim,
yes that's what I did exactly. That's amazing. if you force your tables to "Cascade Delete", and you delete a row in a parent table, all the rows in the childs tables will also be removed :)
Thanks
You got it.... glad it helped you
Jim
No comments:
Post a Comment