SqlServer的T-Sql
如下:

表结构:
字段名         id      title      content
类型            int      char(200)   text
Insert Into News (title,content) Values (@title,@content)

实际上这样插入是不能超过8000字节的(content字段)。SqlServer在这方面做了限制。

可以这样插入

SqlServer Text类型字段超过8000字处理CREATE PROCEDURE NewsInsert   @title char(200),@content text   AS
SqlServer Text类型字段超过8000字处理
SqlServer Text类型字段超过8000字处理
Insert Into News (title,content) Values (@title,'')
SqlServer Text类型字段超过8000字处理
SqlServer Text类型字段超过8000字处理
DECLARE @ptrval binary(16)
SqlServer Text类型字段超过8000字处理
SELECT @ptrval = TEXTPTR(content) 
SqlServer Text类型字段超过8000字处理
FROM News 
SqlServer Text类型字段超过8000字处理
WHERE id = @@identity
SqlServer Text类型字段超过8000字处理
writeTEXT News .content @ptrval  @content
SqlServer Text类型字段超过8000字处理
SqlServer Text类型字段超过8000字处理
GO


用到了writeTEXT函数。
注意:插入的时候Insert Into News (title,content) Values (@title,'')一定要有content值对应空不能让content是null状态.否则下面的无法找到地址。


更新的时候:
SqlServer Text类型字段超过8000字处理CREATE PROCEDURE NewsInsert   @title char(200),@content text,@id int   AS
SqlServer Text类型字段超过8000字处理
SqlServer Text类型字段超过8000字处理
Update News Set title = @title,content='' Where id = @id --注意content=''虽然不起作用,但是最好写上,避免content有null的情况
SqlServer Text类型字段超过8000字处理

SqlServer Text类型字段超过8000字处理
DECLARE @ptrval binary(16)
SqlServer Text类型字段超过8000字处理
SELECT @ptrval = TEXTPTR(content) 
SqlServer Text类型字段超过8000字处理
FROM News 
SqlServer Text类型字段超过8000字处理
WHERE id = @id
SqlServer Text类型字段超过8000字处理
writeTEXT News .content @ptrval  @content
SqlServer Text类型字段超过8000字处理
SqlServer Text类型字段超过8000字处理
GO

读取和删除的时候一切正常,就不多叙述了。
以上用法可以插入数据库类型Text对应的理论实际长度以内。

相关文章:

  • 2021-08-15
  • 2021-08-22
  • 2022-03-03
  • 2021-12-31
  • 2022-01-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2021-12-08
相关资源
相似解决方案