SQL Server text field exceeds 8000 characters

Source: Internet
Author: User
SQL Server T-SQL
As follows:

Table Structure:
Field name ID title content
Int char (200) Text
Insert into news (title, content) values (@ title, @ content)

In fact, the content field cannot exceed 8000 bytes ). Sqlserver imposes restrictions on this.

You can insert

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

UsedWritetext function.
Note: when insertingInsert IntoNews (title, content)Values(@ Title,''Must have a blank content value. content cannot be set to null. Otherwise, the following cannot be found.

When updating: Create   Procedure Newsinsert @ Title   Char ( 200 ), @ Content   Text , @ ID   Int As

Update News Set Title =   @ Title , Content = ''   Where ID =   @ ID   -- Note that content = ''does not work, but it is best to write it to avoid null content.

Declare   @ Ptrval   Binary ( 16 )
Select   @ Ptrval   =   Textptr (Content)
From News
Where ID =   @ ID
Writetext News. Content @ Ptrval @ Content

Go


When reading and deleting data, everything is normal.
The above usage can be inserted within the actual theoretical length corresponding to the database type text.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.