UPDATE with ORDER BY

后端 未结 6 2309
Happy的楠姐
Happy的楠姐 2020-12-11 01:30

Need to "tie" UPDATE with ORDER BY. I\'m trying to use cursors, but get the error:

cursor "cursupd"         


        
6条回答
  •  时光取名叫无心
    2020-12-11 02:15

    This worked for me:

    [update statement here] OPTION (MAXDOP 1) -- prevent row size from causing use of an eager spool, which mutilates the order in which records are updated.

    I use a clustered int index in sequential order (generating one if needed) and hadn't had a problem until recently, and even then only on small rowsets that (counterintuitively) the query plan optimizer decided to use a lazy spool on.

    Theoretically I could use the new option to disallow spool use, but I find maxdop simpler.

    I am in a unique situation because the calculations are isolated (single user). A different situation may require an alternative to using maxdop limit to avoid contention.

提交回复
热议问题