Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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
Author
Message
Posted Wednesday, August 27, 2014 11:11 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, October 13, 2014 4:52 PM
Points: 101, Visits: 236
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'
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: Monday, November 24, 2014 4:53 AM
Points: 3,422, Visits: 5,368
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!
Post #1609876
Posted Thursday, September 4, 2014 12:10 AM


Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, September 4, 2014 12:10 AM
Points: 18, Visits: 162
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