Updating multiple Tables with one UPDATE Statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ricardusmaximus
    New Member
    • May 2015
    • 11

    #1

    Updating multiple Tables with one UPDATE Statement

    I would like to be able to update any number of Tables in a Database by referencing another Table that has the data that needs to be updated using INNER JOINS.

    Tbl1, Tbl2, Tbl3.
    TempTbl.

    The fileds in Tb;1- Tbl3 that are to be updated would be ID.
    TempTbl would have 2 fields: OldID, NewID

    Code:
     UPDATE Tbl1, Tbl2, Tbl3
           ((INNER JOIN TempTbl ON Tbl1.ID = TempTlb.OldID)
           (INNER JOIN TempTbl ON Tbl2.ID = TempTlb.OldID))
            INNER JOIN TempTbl ON Tbl3.ID = TempTlb.OldID
           SET Tbl1.ID = TempTbl.NewID,Tbl2.ID =
              TempTbl.NewID,Tbl3.ID = TempTbl.NewID;
    This didn't work for me. The idea is to be able to do it for an arbitrary number of tables.

    Thank you.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    Father Christmas being real would be nice too.

    You don't really ask a question, but if I were interested in updating multiple tables concurrently via a single UPDATE SQL command I'd start by getting and updatable SELECT statement and then converting that to an UPDATE. If that enabled updating of fields from more than one of the underlying tables then I'd count myself lucky.

    Comment

    Working...