简体   繁体   中英

SQL Server - updating Varchar(max) column using stored procedure

I have table containing column Email which is varchar(MAX) and I am trying to update it using stored procedure. When the string length is greater than 8000 characters, I get this error

String or binary data would be truncated. The statement has been terminated.

Stored procedure:

ALTER PROCEDURE [dbo].[SaveData]
    @Id BIGINT,
    @Email varchar(max)
AS
BEGIN
    SET NOCOUNT ON;

    UPDATE tb_data
    SET Email = @Email
    WHERE Id = @Id  
END

Please note that datatype for email is set to varchar(MAX)

Interesting thing is when I try to run the update query manually, it works!

I've done this several times but cannot figure out why it's not working in this case.

Hope this can help you:

Microsoft MSDN

Maximum Capacity Specifications for SQL Server

1 byte = 1 character >> 2^31-1 characters

varchar [ ( n | max ) ]

Variable-length, non-Unicode string data. n defines the string length and can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size is the actual length of the data entered + 2 bytes. The ISO synonyms for varchar are char varying or character varying.

How many characters in varchar(max)

Maximum size of a varchar(max) variable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM