update query

  • Must be a monday morning brain cramp. Is it possible to run an UPDATE query where the SET operation updates values in two different tables?

     

    Update T1

    set T1.col2='X', T2.col2='Y'

    from T1

    joinT2 on T1.col1=T2.col1

  • No. That's not possible. You can only update one table at a time unless that table has triggers which update other tables.

    I suspect you just need to do this...

    Update T1 set col2 = 'X' from T1 join T2 on T1.col1 = T2.col1

    Update T2 set col2 = 'Y' from T1 join T2 on T1.col1 = T2.col1

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply