Update in Place

When an update is performed in-place, a log record of type MODIFY is recorded in the log. This record contains only the differences between the old and new row values, not their actual values, and it cannot handle changes in row length. For in-place updates, the following restrictions apply:

create table t1 (col1 int, col2 char(60))

go

insert t1 values

(1,'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz')

insert t1 values

(2,'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz')

— continue for 1000 rows —

go

create unique index idx1 on t1 (col1)

go

If you try to change more than one half of the row size—do not confuse this with one half of the column length—delete/insert is performed instead of in-place. Since this example changes 33 bytes of a 64-byte row size, delete/insert is performed.

update t1 set col2 =

'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzhijklmnopqrstuvwxyz'

where col1 = 1

go

If you have more than three differing blocks within the column being updated, delete/insert is performed. Since this example changes 4 bytes, each in a separate block, delete/insert is performed.

update t1 set col2 =

'ZbcdefghijZlmnopqrstuvZxyzabcdefghijkZmnopqrstuvwxyz'

where col1 = 2

go

For single-row, in-place updates, the optimizer must be able to determine ahead of time that only one row will qualify. That is, there must be a unique index, and that index must be used to drive the search. The column being updated can be a nonclustered index key, and that index may also be used to drive the search.

Multiple rows can be updated in-place but only if the following conditions apply: