Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete rows in associated SQL tables?

I want to delete rows in GlassesColor table that associated with GlassesID in Glasses table. I want to implement this in stored procedure.The stored procedure gets only one parameter from client side , a CollectionID.

Here are the following tables:

enter image description here

Here is example of tables content:

enter image description here

Any idea how can i implement this? Thank you in advance!

like image 547
Michael Avatar asked Dec 10 '22 02:12

Michael


1 Answers

Manually deleting would be something like this:

delete 
from GlassesColor 
where GlassesID in (select GlassesID from Glasses where CollectionID = 3)

However, unless this is a one time cleanup, you should start specifying foreign key cascading rules, like the other answers already suggested.

like image 95
Adriano Carneiro Avatar answered Dec 11 '22 14:12

Adriano Carneiro