Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not sure how to implement Mysql if-else statement

Status
Not open for further replies.

s0crates9

Technical User
Jun 18, 2005
70
0
0
US
I have three tables in my test db. we will call them, "category","item" and "data". What I want to do it have a delete statement that will remove the selected "category" ID then look for "items" or "data" that are associated with the "category" being deleted.

I am not sure how to do this, but I believe it's possible. the "category" ID is also refered to in the "item" table but the "data" table does not have a "category" ID, rather the "data" table has an "item" ID referenced to the "item" table. An illustration of sorts:

Category
catid
catname

Item
itemid
itemname
catid

Data
dataid
dataname
itemid

Anyone know how to properly set it up to determine if there is any data in "item" or "data" to be deleted once the "category" table is set for deletion?

Thanks in advance!

Web site design, internet marketing, SEO and business solutions company.
 
i think this is a fabulous opportunity to implement ON DELETE CASCADE

when you delete a category, the database automatically deletes all items in the category, and also, all data rows for items in that category

look on the mysql site under FOREIGN KEY, because that is how you implement ON DELETE CASCADE

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top