How to update two tables data with JOIN in Single query

  • Dwain Camps

    SSC Guru

    Points: 86893

    ChrisM@Work (8/29/2012)


    dwain.c (8/29/2012)


    Yep. That's the same error I got.

    Whatever it is saying, it's odd.

    It refers to "fields" too - and took me ages to call them "columns" when I moved from Visual Foxpro to SQL Server.

    Next time someone barks "They're not 'fields', they're 'columns'", you know what to do 😀

    ROFL. I know who barks that! Gotta save that error message for sure.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • Dwain Camps

    SSC Guru

    Points: 86893

    ChrisM@Work (8/29/2012)


    dwain.c (8/29/2012)


    Yep. That's the same error I got.

    Whatever it is saying, it's odd.

    It refers to "fields" too - and took me ages to call them "columns" when I moved from Visual Foxpro to SQL Server.

    Next time someone barks "They're not 'fields', they're 'columns'", you know what to do 😀

    ROFL. I know who barks that! Gotta save that error message for sure.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • Larry Kruse

    SSCrazy

    Points: 2617

    If you're intending to update two different tables like this, I think you pretty much HAVE to wrapper it in a transaction...otherwise you have a possibility of inserting or updating data in one table without inserting/updating the other table. If an update fails due to a duplicate key or other constraint issue, I would think you'd want both updates/inserts to be paired, so if the first table gets updated and the second one fails, then you'd want to rollback the first table's updates.

    I solved this by creating an updateable view using triggers. I'll scour around and see if I can dig it out of my old notes if you'd like.

Viewing 3 posts - 16 through 18 (of 18 total)

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