Permits nonlogged, interactive updating of an existing text, ntext, or image column. This statement completely overwrites any existing data in the column it affects. WRITETEXT cannot be used on text, ntext, and image columns in views.
WRITETEXT {table.column text_ptr}
[WITH LOG] {data}
Use WRITETEXT to replace text, ntext, and image data and UPDATETEXT to modify text, ntext, and image data. UPDATETEXT is more flexible because it changes only a portion of a text, ntext, or image column rather than the entire column.
By default, WRITETEXT is a nonlogged operation. This means text, ntext, or image data is not logged when it is written to the database; therefore, the transaction log does not fill up with the large amounts of data that often make up these data types. To use WRITETEXT in its default, nonlogged state, members of the sysadmin fixed database role must use sp_dboption to set select into/bulkcopy, which allows nonlogged data to be inserted. For more information, see sp_dboption and Setting Database Options.
For WRITETEXT to work properly, the column must already contain a valid text pointer.
Microsoft® SQL Server™ saves space by not initializing text columns when explicit or implicit null values are placed in text columns with INSERT.
The DB-Library dbwritetext and dbmoretext functions and the ODBC SQLPutData function are faster and use less dynamic memory than WRITETEXT. These functions can insert up to 2 gigabytes of text, ntext, or image data.
Caution After using the WRITETEXT statement, execute BACKUP DATABASE. After nonlogged operations occur within a database, the BACKUP LOG statement cannot be performed. For more information, see BACKUP.
To initialize text columns to NULL, use UPDATETEXT when the compatibility level is set to 65. If the compatibility level is set to 70, use WRITETEXT to initialize text columns to NULL; otherwise, UPDATETEXT initializes text columns to an empty string. For more information about compatibility levels, see sp_dbcmptlevel.
WRITETEXT permissions default to those users with SELECT permissions on the specified table. Permissions are transferable when SELECT permissions are transferred.
This example puts the text pointer into the local variable @ptrval, and then WRITETEXT places the new text string into the row pointed to by @ptrval.
USE pubs
GO
EXEC sp_dboption 'pubs', 'select into/bulkcopy', 'true'
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'
WRITETEXT pub_info.pr_info @ptrval 'New Moon Books (NMB) has just released another top ten publication. With the latest publication this makes NMB the hottest new publisher of the year!'
GO
EXEC sp_dboption 'pubs', 'select into/bulkcopy', 'false'
GO
Data Types | SELECT |
DECLARE @local_variable | SET |
DELETE | UPDATETEXT |