Permits minimally logged, interactive updating of an existing text, unitext or image column.
writetext [[database.]owner.]table_name.column_name text_pointer [readpast] [with log] data
The readpast option applies only to data-only-locked tables. readpast is ignored if it is specified for an allpages-locked table.
If the session-wide isolation level is 3, the readpast option is silently ignored.
If the transaction isolation level for a session is 0, writetext commands using readpast do not issue warning messages. These commands at session isolation level 0 modify the specified text column if the text column is not locked with incompatible locks.
declare @val varbinary (16) select @val = textptr (copy) from blurbs where au_id = "409-56-7008" writetext blurbs.copy @val with log "hello world"
declare @val varbinary (16) select @val = textptr (copy) from blurbs readpast where au_id = "409-56-7008" writetext blurbs.copy @val readpast with log "hello world"
declare @val varbinary (16) select @val = textptr (ut) from unitable where i = 100 writetext unitable.ut @val with log "Hello world"
The varchar constant is implicitly converted to unitext before the column is updated.
The maximum length of text that can be inserted interactively with writetext is approximately 120K bytes for text, unitext or image data.
By default, writetext is a minimally logged operation; only page allocations and deallocations are logged, but the text, unitext or image data is not logged when it is written into the database. To use writetext in its default, minimally logged state, a system administrator must use sp_dboption to set select into/bulkcopy/pllsort to true.
writetext updates text data in an existing row. The update completely replaces all of the existing text.
writetext operations are not caught by an insert or update trigger and for this reason, updating with writetext does not result in an update of the row timestamp.
writetext requires a valid text pointer to the text, unitext or image column. For a valid text pointer to exist, a text, or unitext column must contain either actual data or a null value that has been explicitly entered with update.
update textnull set x = null
insert textnull values (2,null)
insert textnull (textid) values (2)
insert and update on text columns are logged operations.
You cannot use writetext on text and image columns in views.
If you attempt to use writetext on text values after changing to a multibyte character set, and you have not run dbcc fix_text, the command fails, and an error message is generated, instructing you to run dbcc fix_text on the table.
writetext in its default, non-logged mode runs more slowly while a dump database is taking place.
The Client-Library functions dbwritetext and dbmoretext are faster and use less dynamic memory than writetext. These functions can insert up to 2GB of text data.
See also Converting text and image Datatypes in Reference Manual: Building Blocks.
ANSI SQL – Compliance level: Transact-SQL extension.
You must be the table owner or a user with update permission to run writetext.