摘要:
下文讲述updatetext的功能及举例说明
实验环境:sql server 2008 R2
updatetext关键字功能及语法说明
updatetext功能说明: updatetext的功能为:更新当前的text,ntext,image字段, 当我们可以使用updatetext更新列中的部分数据 updatetext语法简介:
- UPDATETEXT [BULK] { table_name.dest_column_name dest_text_ptr }
- { NULL | insert_offset }
- { NULL | delete_length }
- [ WITH LOG ]
- [ inserted_data
- | { table_name.src_column_name src_text_ptr } ]
-
-----参数说明-------------------------
BULK:
是否采用二进制数据流,非采用二进制数据流,此参数无需输入
table_name.dest_column_name table_name:
待更新的表名
dest_column_name:
待更新的列名(列需为text,ntext,image)类型,名称必须符合相应的规则。
dest_text_ptr:
待更新text,ntext,image的值(需为二进制(16)),此值由textptr函数生成并返回。
insert_offset:
以0作为起始值, 在text,image列中,insert_offset为数据插入的开始值,(注意:ntext类型中每个字符占用2个字节), 如果列中的值为null,则表示数据追加
delete_length:
由 insert_offset 位置开始的、要从现有 text、ntext 或 image 列中删除的数据长度。 delete_length 值为 text 和 image 列指定时以字节为单位,为 ntext 列指定时以字符为单位。 每个 ntext 字符占用 2 个字节。 值为 0 表示不删除数据。 值为 NULL 则删除现有 text 或 image 列中从 insert_offset 位置开始到末尾的所有数据。
WITH LOG:
在 SQL Server 2000 中被忽略。在 SQL Server 2005 中,日志记录由数据库的实际恢复模型决定。
inserted_data
待插入到 insert_offset 位置现有 text、ntext 或 image 列中的数据。 此处数据可以由单个 char、nchar、varchar、nvarchar、binary、varbinary、text、ntext 或 image 值。 inserted_data 可以是文字或变量。
table_name.src_column_name:
用作插入数据源的表和 text、ntext 或 image 列的名称。 表名和列名必须符合标识符规则。
src_text_ptr
指向用作插入数据源的 text、ntext 或 image 列的文本指针值(由 TEXTPTR 函数返回)。
updatetext关键字举例应用
-
-
- create table [maomao365.com]
- (keyId int identity,
- info ntext)
- go
-
- insert into [maomao365.com]
- (info)values(N'sql博客教程'),
- (N'sqlserver学习'),
- (N'sqkserver爱好者')
- go
-
-
- ---定义一个十六进制变量
- declare @info_e binary(16)
-
- --从源表中获取变量信息
- select @info_e = textptr(info)
- from [maomao365.com]
- where keyId =1
-
- ---更新变量信息,
- ---从第二个字符开始,删除字符为0,插入字段
- updatetext [maomao365.com].info @info_e
- 2 0 N'新增字段'
-
- ---查看表数据
- select * from [maomao365.com]
-
-
-
- go
- truncate table [maomao365.com]
- drop table [maomao365.com]
[caption id="attachment_7804" align="alignnone" width="443"]
mssql_sqlserver_updatetext[/caption]
转自: http://www.maomao365.com/?p=7802