SqlServer的T-Sql
如下:
表結構:
字段名 id title content
類型 int char(200) text
Insert Into News (title,content) Values (@title,@content)
實際上這樣插入是不能超過8000字節的(content字段)。SqlServer在這方面做了限制。
可以這樣插入

CREATE PROCEDURE NewsInsert @title char(200),@content text AS


Insert Into News (title,content) Values (@title,'')


DECLARE @ptrval binary(16)

SELECT @ptrval = TEXTPTR(content)

FROM News

WHERE id = @@identity

writeTEXT News .content @ptrval @content


GO
用到了writeTEXT
函數。
注意:插入的時候Insert Into News (title,content) Values (@title,'')一定要有content值對應空,不能讓content是null狀態.否則下面的無法找到地址。
更新的時候:
CREATE PROCEDURE NewsInsert @title char(200),@content text,@id int AS

Update News Set title = @title,content='' Where id = @id --注意content=''雖然不起作用,但是最好寫上,避免content有null的情況

DECLARE @ptrval binary(16)
SELECT @ptrval = TEXTPTR(content)
FROM News
WHERE id = @id
writeTEXT News .content @ptrval @content

GO讀取和刪除的時候一切正常,就不多敘述了。
以上用法可以插入數據庫類型Text對應的理論實際長度以內。
關鍵詞: