在sql2005中增强了update语句的功能,对于类似nvarchar(max), nvarchar(max), or varbinary(max)之类的字段类型提供了write 功能。
Example:
create table testBIGtext
(
testBIGtextId int PRIMARY KEY,
value varchar(max)
)
go
insert into testBIGtext
values(1,'')
接下来我们用write来更新value字段的值:
(
testBIGtextId int PRIMARY KEY,
value varchar(max)
)
go
insert into testBIGtext
values(1,'')
DECLARE @offset int
SET @offset = 0
WHILE @offset < 26
BEGIN
UPDATE testBIGtext
SET value.write(replicate(char(97 + @offset),1000),@offset*1000, 1000)
WHERE testBIGTextId = 1
SET @offset = @offset + 1
END
执行以后,value值将是1000个a连着1000个b...(aaaa...bbb.ccc......zzz)
SET @offset = 0
WHILE @offset < 26
BEGIN
UPDATE testBIGtext
SET value.write(replicate(char(97 + @offset),1000),@offset*1000, 1000)
WHERE testBIGTextId = 1
SET @offset = @offset + 1
END