The varchar in MSSQL (T-SQL) does not specify the size as though there is generally only one length

Source: Internet
Author: User

Today, I occasionally want to rewrite the previously written trigger and find some problems.

For example, the followingCode:

 

Declare...

...

@ Devicetype_ori int,
@ Productor_ori varchar,
@ Version_ori varchar,
@ Beginruntime_ori datetime,
@ Devicemodel_ori varchar;

 

I am worried about what the length will be if varchar does not define it accurately. I checked the varchar description.

Found

(From

Http://bbs.csdn.net/topics/60020321

An answer

)

Varchar [(n)]
Variable-length and non-UNICODE character data with a length of n Bytes. N must be a value between 1 and 8,000. The storage size is the actual length of the input data bytes, rather than n Bytes. The length of the input data can be zero. The synonym for varchar in the SQL-92 is Char varying or character varying.

When declaring varchar type variables, you can leave the length unspecified, but there may be problems.
E. g:
Declare @ AA varchar
Set @ AA = 'asdafdadfs'
Print (@ aa)
-- Result:
A

 

So the trigger does not report an error, but it will not achieve the purpose we want...

Be careful...

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.