Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update from inner SQL
Message
From
01/03/2011 18:54:48
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01502274
Message ID:
01502301
Views:
29
>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.

Ok, yes, for that part I agree that a one to many relationship could cause disastrous updates. I will double check that. But, I think what was sent to me was querying into a single record for the relationship.

What I was mostly concentrated about was the Update clause, the first line. Your syntax is also using the alias but avoids using it in the Set clause. I guess it can be omitted at that level as there is no confusion on which table the update will be done.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Reply
Map
View

Click here to load this message in the networking platform