updating column with data validation from other master table

  • I have two tables

    CustomerOrders

    Country

    I would like to write a Update statement on customer order table with validation from country table.

    Update CustomerOrders

    set CustomerOrders.Country = 'DDDDD'

    validation country from country table.

    The above statement will throw error as there is no country 'DDDDD'

  • Sounds like you want to add a foreign key relationship between the Country column in your CustomerOrders table to the country code in your Countries table.


    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

  • seems like you want inner join on table to be updated and country table on country='DDDDD'

    check attachment

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

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