String or binary data would be truncated

 267 Total Views,  4 views today

This recipe will demonstrate how to Fix Sql Server
Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated. The statement has been terminated.

It simply means that you are inserting or updating a column value that is greater than the column maximum allowed value.
Example: A column can only hold up to 5 characters, but you are inserting more than 5 character string.

First create Problem:
CREATE TABLE employee (
EmpID INT NOT NULL ,
EmpName VARCHAR(10))
GO

INSERT INTO employee ( EmpID, EmpName )
VALUES (1, ‘Leonel Messi’)
GO
Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated. The statement has been terminated.

Error Explain: Here EmpName column can only hold up to 10 characters, but you are inserting 12 character string.

Solution:
1) Either increase the length or size of the EmpName column to 12 character in employee table.
OR
2) Decrease the value of the EmpName field to 10 character in values clause.

Example:

INSERT INTO employee ( EmpID, EmpName )
VALUES (1, ‘Messi’)
GO

1 thought on “String or binary data would be truncated”

Leave a Reply

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