I have a question. I have two tables:
-
zip_code (zip_id, zip_code, state) – this is a static table that
stores areas I service -
tech_zips (tz_id, tech_id, zip) – this is where I store what zip codes a
specific tech services
So, on my form, I have a select list that chooses a tech and a textarea to paste in zip codes. This works fine, except it doesn't take into consideration whether or not I service a zip code.
Instead of coming up with crazy arrays and whatnot in PHP – I figured a trigger would be easier, except I know nothing about them. 🙁
How would I write a trigger that does this: When a new zip code is inserted into tech_zips, the trigger sees whether or not that zip exists in the zip_code table. If it doesn't, then it deletes it.
Thanks for any help! Oh, I have phpmyadmin.
Best Answer
Well, it's a crazy and novel idea, but you might consider that this is what foreign key constraints are actually for... you can't insert a row in table "x" if a column there has a foreign key constraint against a column in table "y" but the value you're inserting in "x" doesn't exist in "y"...