Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update from inner SQL
Message
 
 
To
01/03/2011 18:37:04
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01502274
Message ID:
01502291
Views:
26
>>If we're not careful and there is no direct relationship (1 to 1) between table we're updating and a second table, we may end up updating wrong data.
>
>So, when using an alias, such as the first example I showed, is this considered direct relationship? If yes, then, this would mean using alias, such as in that example, is safe. Can you confirm that?

No, what I mean is this

Orders
OrderDetail
Update O set OrderQty = OD.Qty
from Orders O
inner join OrderDetail OD 
on O.OrderID = OD.OrderID
In this case one Order has multiple OrderDetails records. Using the update I showed (perfect syntax), we don't know what we will end up with since one record in Order table corresponds to multiple records in the OrderDetails.

If in your update you can guarantee, that each record you're updating has one (or 0) corresponding records in the other table, then you should be OK.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform