SQL Server "String or Binary Data Would Be Truncated": Fix Msg 8152 & 2628
By Sharon Ben-Moshe · September 20, 2026 · 1 min read
Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
Fix SQL Server Error 8152 and 2628: String or binary data would be truncated. Discover how to identify the offending column and increase column size.
Quick answer
This error occurs when attempting to insert or update a string or byte array longer than the target column's defined length (e.g. inserting 60 characters into VARCHAR(50)). On SQL Server 2019+, error Msg 2628 explicitly lists the table, column, and truncated value. On older versions, enable trace flag 460 or query column LEN() to identify the offending payload.
FAQs
What is the difference between SQL Server Msg 8152 and Msg 2628?
Msg 8152 was the legacy, notorious message that gave no column name. Starting in SQL Server 2019 (and 2016 SP2 CU6 / 2017 CU12), Microsoft introduced Msg 2628, which states: 'String or binary data would be truncated in table X, column Y. Truncated value: Z'.
How do I enable verbose truncation messages on SQL Server 2017?
Run `DBCC TRACEON (460, -1);` or enable the database-scoped configuration: `ALTER DATABASE SCOPED CONFIGURATION SET VERBOSE_TRUNCATION_WARNINGS = ON;`.
Can I silently truncate text instead of throwing an error?
Yes, by wrapping the input with `LEFT(input_column, 50)`. However, silently truncating data often corrupts email addresses, hash tokens, or JSON payloads and is discouraged.
Does VARCHAR(MAX) prevent truncation errors?
Yes, VARCHAR(MAX) can store up to 2GB of data. However, using MAX indiscriminately prevents index key creation and degrades memory grant estimates.
Keep reading
Fix BigQuery "Unrecognized Name" Error: Scoping and Syntax Rules
By Sharon Ben-Moshe · Sep 29, 2026
Fix Google BigQuery's "Unrecognized name: column" error. Learn alias visibility rules across WHERE and QUALIFY, case sensitivity, and struct unnesting.
Read postSQLite "Datatype Mismatch" (Error 20): Type Affinity and Strict Tables
By Sharon Ben-Moshe · Sep 26, 2026
Understand SQLite Error 20 (datatype mismatch). Learn how SQLite type affinity, CHECK constraints, and STRICT tables enforce data integrity.
Read postTry it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.