Subject Re: [firebird-support] Multiple table update question
Author Helen Borrie
At 04:50 PM 8/04/2005 +1000, you wrote:

>Hi,
>
>Is this legal in FB? perform UPDATE operations that cover multiple tables?
>
>UPDATE items, month SET items.price=month.price
>WHERE items.id=month.id;

No, it's not legal. An UPDATE statement updates rows in a single table only.


>If it is, what Am I doing wrong, as when I try to run it on IBConsole I get
>errors regarding the , between table names.

You can write an executable stored procedure if you need to update multiple
tables. Make sure that the input arguments include all of the keys you
will need to locate the exact records for updating.

However, in this case (unless you aren't telling everything) you are not
updating multiple tables, only one (items):

update items i
set i.price = (select m.price from month m
where i.id = m.id)

The logic for this can only work, of course, if there is a 1:0 or 1:1 match
between the two id fields. If your structure doesn't provide this logic,
i.e. is potentially 1:Many (or something else), then either you need to
provide an intersection table or you have to write an executable SP.

./hb



>Thanks
>
>daniel
>
>____________________________
>Comvision Pty. Ltd.
>
>www.comvision.net.au
>
>
>
>
>Yahoo! Groups Links
>
>
>
>