patternsqlMajor
Is there an efficient way to see the cause for "String or binary data would be truncated"?
Viewed 0 times
thetruncatedefficientwayseewouldbinaryforcausethere
Problem
This is a follow-up on this question. It is also related to this feature request from Microsoft.
However, many years have passed and several major releases reached the market since it was reported.
Question: does SQL Server 2017 provide any mechanism to ease finding out the root cause of this error? Or it is as hard to investigate as it was about 9 years ago when the issue was reported?
However, many years have passed and several major releases reached the market since it was reported.
Question: does SQL Server 2017 provide any mechanism to ease finding out the root cause of this error? Or it is as hard to investigate as it was about 9 years ago when the issue was reported?
Solution
There has been no change. SQL Server 2017 still offers up the same vague error message and does not provide any mechanism to discover the offending row/column.
This Connect item had over 1,600 votes when Connect was retired (and the new item in Azure Feedback was not ported when they moved the content yet again):
The latest comment there, from Microsoft, was this:
Latest update - the developer working on it understands the challenges involved in creating a full fix. It may be tricky to plumb the information about columns needed to generate a full error message down to the actual conversion function in such a way that won't impact insert or update performance. We may implement something cheap in the short term such as logging the type and length of the data being truncated. It's still too early to know when such a fix would reach a publicly visible release.
Since then, this has been fixed (as later answers and comments suggest). To get the more verbose message (stealing shamelessly from Brent's post):
SQL Server 2016 SP2 CU6+, 2017 CU12+, 2019:
SQL Server 2019
However, be careful with 460, as this bug is still under review.
This Connect item had over 1,600 votes when Connect was retired (and the new item in Azure Feedback was not ported when they moved the content yet again):
- Please fix the "String or binary data would be truncated" message to give the column name
The latest comment there, from Microsoft, was this:
Latest update - the developer working on it understands the challenges involved in creating a full fix. It may be tricky to plumb the information about columns needed to generate a full error message down to the actual conversion function in such a way that won't impact insert or update performance. We may implement something cheap in the short term such as logging the type and length of the data being truncated. It's still too early to know when such a fix would reach a publicly visible release.
Since then, this has been fixed (as later answers and comments suggest). To get the more verbose message (stealing shamelessly from Brent's post):
SQL Server 2016 SP2 CU6+, 2017 CU12+, 2019:
-- server-level:
DBCC TRACEON(460, -1);
-- query-level:
... OPTION (QUERYTRACEON 460);SQL Server 2019
-- 2019 adds a database-level option:
ALTER DATABASE SCOPED CONFIGURATION
SET VERBOSE_TRUNCATION_WARNINGS = ON;However, be careful with 460, as this bug is still under review.
Code Snippets
-- server-level:
DBCC TRACEON(460, -1);
-- query-level:
... OPTION (QUERYTRACEON 460);-- 2019 adds a database-level option:
ALTER DATABASE SCOPED CONFIGURATION
SET VERBOSE_TRUNCATION_WARNINGS = ON;Context
StackExchange Database Administrators Q#196229, answer score: 20
Revisions (0)
No revisions yet.