Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

when calling UPDATE from the result set of a SELECT statem..

 
   Database Forums (Home) -> Clustering RSS
Next:  how to find out if a TSQL table is being updated?  
Author Message
DR

External


Since: Oct 23, 2007
Posts: 27



(Msg. 1) Posted: Fri Nov 30, 2007 6:38 pm
Post subject: when calling UPDATE from the result set of a SELECT statement, is the order in which rows from the SELECT statement 100% geronteed?
Archived from groups: microsoft>public>sqlserver>clustering (more info?)

when calling UPDATE from the result set of a SELECT statement, is the order
in which rows from the SELECT statement 100% geronteed?

tableA

myid
-----------
0
1
2
3
4
5

UPDATE tableB u
SET myid = i.myid
FROM tableA i
ORDER BY myid

Will this always update tableB with 5 since it is the last one? is this 100%
garonteed to follow the order of the source result set?

 >> Stay informed about: when calling UPDATE from the result set of a SELECT statem.. 
Back to top
Login to vote
Linchi Shea

External


Since: Mar 03, 2006
Posts: 234



(Msg. 2) Posted: Sat Dec 01, 2007 7:25 am
Post subject: RE: when calling UPDATE from the result set of a SELECT statement, is [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Most likely, you'll get the first value (BTW, remove the OREDER BY clause).
But that is not guaranteed at all. BOL explicitly documents this scenario as
undefined/nondeterministic:

"The results of an UPDATE statement are undefined if the statement includes
a FROM clause that is not specified in such a way that only one value is
available for each column occurrence that is updated, that is if the UPDATE
statement is not deterministic."

For an example of UPDATE nondeterminism at work, see
http://sqlblog.com/blogs/linchi_shea/archive/2007/11/13/nondeterminist...update.

Linchi

"DR" wrote:

> when calling UPDATE from the result set of a SELECT statement, is the order
> in which rows from the SELECT statement 100% geronteed?
>
> tableA
>
> myid
> -----------
> 0
> 1
> 2
> 3
> 4
> 5
>
> UPDATE tableB u
> SET myid = i.myid
> FROM tableA i
> ORDER BY myid
>
> Will this always update tableB with 5 since it is the last one? is this 100%
> garonteed to follow the order of the source result set?
>
>
>

 >> Stay informed about: when calling UPDATE from the result set of a SELECT statem.. 
Back to top
Login to vote
Display posts from previous:   
   Database Forums (Home) -> Clustering All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]