0

How can we update multiple columns in multiple tables in a single query?

I tried the below but no success.


My tables

update Class c, School s
set c.Status='Absent', s.Status='Absent'
Where c.ID='&ID' and c.ID=s.ID;

Any clues are appreciable.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
King
  • 5
  • 5

1 Answers1

0

You can't do a direct update of multiple tables in Oracle.

You might be able to do an update of a view, like this:

update (
select c.status class_status, s.status school_status
from Class c, School s
Where c.ID='&ID' and c.ID=s.ID )
set class_status='Absent', school_status='Absent'

Oracle will only allow this if the join between the tables preserves keys - i.e. each row produced by the join directly maps to a single row in the source table(s) being updated. I suspect that in this case that School is not key-preserved as each row in that table probably relates to more than one row in Class. So you won't be able to do this in a single statement.

Oracle is far less tolerant of fuzzy relational thinking than other systems.

Dave Costa
  • 47,262
  • 8
  • 56
  • 72