Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

updating column with data validation from other master table Expand / Collapse
Posted Wednesday, August 27, 2014 11:11 AM


Group: General Forum Members
Last Login: Thursday, May 5, 2016 5:20 AM
Points: 114, Visits: 265
I have two tables
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'
Post #1607946
Posted Tuesday, September 2, 2014 11:49 PM

Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Wednesday, February 24, 2016 6:28 AM
Points: 3,977, Visits: 6,431
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!

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?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables
Post #1609876
Posted Thursday, September 4, 2014 12:10 AM



Group: General Forum Members
Last Login: Wednesday, September 2, 2015 9:41 PM
Points: 18, Visits: 169
seems like you want inner join on table to be updated and country table on country='DDDDD'
check attachment

  Post Attachments 
sql1.txt (0 views, 124 bytes)
Post #1610370
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse