In SQL Server, the .WRITE clause is used inside an UPDATE statement to modify only a specific portion of a large value data-type column (varchar(max), nvarchar(max), varbinary(max)). Instead of rewriting the entire value, .WRITE lets you insert, overwrite, or truncate bytes/characters at a given position, improving performance and reducing logging for very large objects. If offset and length are NULL, the expression is appended to the existing value. If expression is NULL, the specified segment is deleted. .WRITE cannot target columns of other data types and must be used with SET. It works on tables, views (with updatable columns), and indexed views when allowed. The operation is fully logged unless the database is in bulk-logged mode, and it is compatible with triggers and constraints like any UPDATE.
expression
- any varchar, nvarchar, or varbinary value to write (can be NULL)@Offset
- bigint; zero-based starting position. NULL appends expression.@Length
- bigint; number of bytes/characters to overwrite. NULL appends expression.UPDATE, varchar(max), nvarchar(max), varbinary(max), BULK INSERT, FILESTREAM
SQL Server 2005
It only works with varchar(max), nvarchar(max), and varbinary(max) columns.
Use NULL for both offset and length: column.WRITE(expression, NULL, NULL).
Yes. .WRITE behaves like any other UPDATE and is fully compatible with triggers.
Yes. It logs only the changed bytes, making it more efficient than updating the entire value.