Error string or binary data would be truncated by update in mssql server

Dung Do Tien Mar 18 2020 459

I have a table as below :

 CREATE TABLE News(
  Id INT IDENTITY(1,1) NOT NULL,
  Title NVARCHAR(100) NOT NULL,
  ShortContent NVARCHAR(1000) NULL
)

In this table have to 100k records and I need update Title column value same with ShortContent column and this is my query:

 UPDATE News SET Title  =  ShortContent

 But I get an error string or binary data would be truncated. the statement has been terminated. Pls leave a comment if you have any suggestions.

Have 1 answer(s) found.
  • D

    Dung Do Tien Mar 18 2020

    Great question

    If you attention you will find that there are two points of interest.

    1. The data type of columns - They are the same

    2. Length of columns - They are the difference

     

     Title NVARCHAR(100) NOT NULL,
    ShortContent NVARCHAR(1000) NULL 

    In your case,  the reason to get this error is points 2, you only need to set length of them are the same. It will be working for you.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close