SQL UPDATE multiple tables - TechRepublic
General discussion
January 12, 2003 at 03:17 AM
mr. origami

SQL UPDATE multiple tables

by mr. origami . Updated 23 years, 5 months ago

How can I update multiple tables (ASP/VBSCRIPT/ACCESS)? Let’s say I have 2 tables, tblFood and tblDrink with the following fields:
tblDrink = drinkID, drinkName
tblFood = foodID, foodType, foodName, alcoholFlag

(Note the tables are not related right now. This is an example – not my real project!)

“foodType” indicates breakfast, lunch, dinner
“alcoholFlag” is currently set to “no” across entire table

Currently, tblDrink lists only soda and tblFood lists all sorts of stuff. If I UPDATE tblDrink to change “creamsoda” to “beer”, I also want to set “alcoholFlag” to “yes” for all foods of type “dinner”.

UPDATE tblDrink SET drinkName=”beer” WHERE drinkName=”creamsoda”

works to update the Drink table – but how do I ALSO set the alcoholFLag in tblFood to a “yes” for all foodType of “dinner”?

Is there such thing as something like this?:
UPDATE tblDrink,tblFood SET ((tblDrink.drinkName=”beer” WHERE tblDrink.drinkName=”creamsoda”) AND (tblFood.alcoholFlag=”yes” WHERE tblFood.foodType=”dinner”))

This discussion is locked

All Comments