How to update multiple tables in sql server 2008 ?

  • Hi All,

    I want to update multiple columns from multiple tables in a single UPDATE Query...

    Just want to do like below query...

    UPDATE Table1, Table2

    SET Table1.Column1 = 'one'

    ,Table2.Column2 = 'two'

    FROM Table1 T1, Table2 T2

    WHERE T1.id = T2.id

    and T1.id = 'id1'

    Does Sql Server 2008 provide any mechanism to do so?

    If Sql Server 2008 provide such nice approach, please share some links with me!

    Thanks!

  • No you cannot do this. Ref BOL here

    The view referenced by table_or_view_name must be updatable and reference exactly one base table in the FROM clause of the view

    ______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience

  • No such feature exists. Wrap the two updates in a single transaction is what you want.

    The probability of survival is inversely proportional to the angle of arrival.

  • Sql Server doesn't allow it but according to MSDN Visual Studio gives you a bypass on that.

    http://msdn.microsoft.com/en-us/library/f5scy1hs(v=VS.80).aspx

  • Thanks,

    But i want to know one thing.

    Is this applicable in SQL Server 2008.

    Reply with your view.....

  • A single update statement can only update a single table, that's in any version of SQL Server

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks,

    got your point!

Viewing 7 posts - 1 through 6 (of 6 total)

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