When a property of text type exists in a database table, you need to be careful when writing SQL statements!

Source: Internet
Author: User

Previously, when writing query statements habitually, the query condition was judged by "=". When writing a program today, the query suddenly reported an error: Data type text and varchar are incompatible in the equal to operator. Looking at the database discovery, where a property (for example, name:) is of type text, then the query condition Name= ' Zhang San ' will give an error. Find related data A property of the text type cannot be judged equal with "=" because it is not supported and can be judged with "like", for example: Name "Zhang San".

There are a few additional points to note:

(1): The text field type cannot be replaced directly with the Replace function, and must be UPDATETEXT

(2): Field comparison cannot use the where field = ' Some data ', you can use like to replace

(3): UPDATETEXT, if the @ptrval value is empty will be an error, you need to note * *

Some people say that text is rarely used now, because in Ms SQL2005 and above, a large data type (varchar (max), nvarchar (max), varbinary (max)) is added. A large value data type can store up to 2^30-1 bytes of data.

These data types behave in the same way as the smaller data types varchar,nvarchar , and varbinary .

Microsoft's argument is that this data type is used instead of the previous text,ntext , and image data types, and the correspondence between them is:

varchar (max)-------text;

nvarchar (max)-----ntext;

varbinary (max)----image.

When a property of text type exists in a database table, you need to be careful when writing SQL statements!

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.