“Msg 8152, Level 16, State 4, Line 1 String or binary data would be truncated. The statement has been terminated.”

 

ERROR MESSAGE:

“Msg 8152, Level 16, State 4, Line 1 String or binary data would be truncated. The statement has been terminated.”

 

EXPLANATION:

If you try to insert more characters than the character length of the column in a table, you will encounter this error and the insert will be canceled.

For example, you have a table named “myTable” and its schema is as follows:

If you try to insert data into this table as follows, there will be no problem.

But if you try to insert a data as follows, you will get an error:

 

Because the name “Abdulrezzak” exceeds the length of 10 characters we assign to the “Name” column when creating the table. Therefore, data cannot be saved and the operation results in this error.

 

SOLUTION:

Increase the width of your column. For example, if we continue from the example above, we will not have a problem with the name “Adbulrezzak” if we set the “Name” column as nvarchar (15). You can set a larger value to suit your needs.

 

You can use the below script. You dont need to recreate the table to increase the width of the column.

Ekrem Önsoy
Author: Ekrem Önsoy

The original article was written in Turkish by Ekrem Önsoy and translated to English by dbtut with the consent of the author. The copyright of the article belongs to the author. The author shall not be liable in any way for any defect caused by translation.

Leave a Reply

Your email address will not be published. Required fields are marked *