Posts Tagged Integer
String or binary data would be truncated error from an Integer Field in SQL Server Database
Posted by A2H in SQL Server on December 17, 2016
Introduction
In this article I am going to explain an interesting problem in SQL Server.
Usually we will see the exception “String or binary data would be truncated” with string datatype columns.
For ex: If you have a column with Datatype Varchar (50) in the table and if you try to insert an entry with more than 50 characters you will get this exception.
To my surprise I faced the same error with an integer column and I tried multiple options to find out from where the exception is thrown. All my changes went in vain and I couldn’t fix with the changes I made in an integer column.
Solution:
After some time I started looking at the Triggers in the table and Bingo, that’s where the problem was and I was able to fix the issue.
In my case when I do an insert to Integer column, I was creating a larger string in trigger and for a particular combination it crossed the allowed 50 character limit which resulted in Error.
Note:
If you face exception during an insert to integer data type column, then First Check the Trigger for your table, the root cause of exception might be in trigger.