UPDATETEXT (Transact-SQL)
Updates an existing text, ntext, or image field. Use UPDATETEXT to change only a part of a text, ntext, or image column in place. Use WRITETEXT to update and replace a whole text, ntext, or image field.
Important
|
|---|
|
This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Use the large-value data types and the .WRITE clause of the UPDATE statement instead. |
Newly inserted data can be a single inserted_data constant, table name, column name, or text pointer.
|
Update action |
UPDATETEXT parameters |
|---|---|
|
To replace existing data |
Specify a nonnull insert_offset value, a nonzero delete_length value, and the new data to be inserted. |
|
To delete existing data |
Specify a nonnull insert_offset value and a nonzero delete_length. Do not specify new data to be inserted. |
|
To insert new data |
Specify the insert_offset value, a delete_length of 0, and the new data to be inserted. |
For best performance we recommend that text, ntext and image data be inserted or updated in chunks sizes that are multiples of 8,040 bytes.
In SQL Server, in-row text pointers to text, ntext, or image data may exist but may not be valid. For information about the text in row option, see sp_tableoption (Transact-SQL). For information about invalidating text pointers, see sp_invalidate_textptr (Transact-SQL).
To initialize text columns to NULL, use WRITETEXT; UPDATETEXT initializes text columns to an empty string.
The following example puts the text pointer into the local variable @ptrval, and then uses UPDATETEXT to update a spelling error.
Note
|
|---|
|
To run this example, you must install the pubs database. |
USE pubs;
GO
ALTER DATABASE pubs SET RECOVERY SIMPLE;
GO
DECLARE @ptrval binary(16);
SELECT @ptrval = TEXTPTR(pr_info)
FROM pub_info pr, publishers p
WHERE p.pub_id = pr.pub_id
AND p.pub_name = 'New Moon Books'
UPDATETEXT pub_info.pr_info @ptrval 88 1 'b';
GO
ALTER DATABASE pubs SET RECOVERY FULL;
GO

Important