SQL Server String or binary data would be truncated

I am involved in a data migration project. I am getting the following error when I try to insert data from one table into another table (SQL Server 2005):

Msg 8152, Level 16, State 13, Line 1
String or binary data would be truncated.

The source data columns match the data type and are within the length definitions of the destination table columns so I am at a loss as to what could be causing this error.


Solution 1:

You will need to post the table definitions for the source and destination tables for us to figure out where the issue is but the bottom line is that one of your columns in the source table is bigger than your destination columns. It could be that you are changing formats in a way you were not aware of. The database model you are moving from is important in figuring that out as well.

Solution 2:

As others have already said, one of your columns datatypes in the source table is larger than your destination columns.

A simple solution is to simply turn off the warning and allow truncation to take place. So, if you're receiving this error but you are sure it is acceptable for data in your old database/table to be truncated (cut to size) you can simply do the following;

SET ANSI_WARNINGS OFF;
-- Your insert TSQL here.
SET ANSI_WARNINGS ON;

As above, always remember to turn warnings back on again afterwards. I hope this helps.