SQL Server engine errors
String or Binary Data Truncated
Reviewed for reference consistency: August 11, 2026
the value exceeds the column's defined length
What 8152 Means
The 8152 error on the SQL Server engine errors indicates string or binary data truncated — the value exceeds the column's defined length. This typically occurs due to an insert or update supplies a value whose length exceeds the column's declared size, such as 50 characters aimed at a varchar(20) column.
Error 8152, 'String or binary data would be truncated', means an INSERT or UPDATE tried to store a value longer than the column's declared size. How strict the engine is depends on the ANSI_WARNINGS setting: ON cancels the statement, OFF silently shortens the value to the column's size and lets the statement succeed. The declared length also counts differently by type, because VARCHAR(n) measures bytes while NVARCHAR(n) measures byte-pairs. Severity 16 places 8152 among the errors a user can correct: the fix is in the data or in the column definition.
How to fix 8152
General informational guidance, not professional advice. Commands can affect your system or data — back up first and proceed at your own risk. FixerCode is an independent reference, not affiliated with any vendor mentioned.
Compare the declared size with the longest stored value
COL_LENGTH returns the column's defined length in bytes and DATALENGTH returns the number of bytes a value uses. An NVARCHAR column stores two bytes per byte-pair, so its longest value can read twice its character count.
SELECT COL_LENGTH('dbo.YourTable', 'YourColumn') AS defined_size, MAX(DATALENGTH(YourColumn)) AS longest_value FROM dbo.YourTable;Turn on the verbose truncation message
Trace flag 460 replaces 8152 with message 2628, which names the table, the column, and the truncated value. From compatibility level 150 that detail is already the default.
DBCC TRACEON (460);Fit the data to the column, or the column to the data
Either trim the incoming value to the declared size before it reaches the statement, or widen the column after checking dependent objects. Switching ANSI_WARNINGS OFF removes the error but replaces it with silent data loss.
Technical Background
Error 8152 is raised at severity 16 when a new value exceeds the maximum size of a character, Unicode, or binary column. The official message is exactly 'String or binary data would be truncated.' and it names no column, nor is it written to the event log. The engine refuses the write instead of storing a shortened value, because the excess characters would be lost without the caller knowing. On the same write path, 515 rejects NULL aimed at a NOT NULL column and 547 rejects rows that violate a constraint.
Which behavior applies depends on ANSI_WARNINGS. With the setting ON, the INSERT or UPDATE is canceled as the ISO standard specifies. With it OFF, the value is truncated to the column's size and the statement succeeds. Two paths truncate silently regardless of the setting: conversions to or from binary or varbinary data, and values passed as stored-procedure parameters or assigned to variables in a batch.
The declared length itself differs by type. For VARCHAR, n defines the string size in bytes, and with multibyte character sets the number of characters that fit can be smaller than n. For NVARCHAR, n defines the size in byte-pairs: under UCS-2 exactly n characters fit, while under UTF-16 supplementary characters take two byte-pairs and reduce that count.
Message 2628 names the table, the column, and the truncated value, and trace flag 460 replaces 8152 with it. The flag is documented for SQL Server 2016 SP2 CU 6 and SQL Server 2017 CU 12 and later versions; from database compatibility level 150, message 2628 is the default, and on SQL Server 2019 and later the same behavior is available per database through the VERBOSE_TRUNCATION_WARNINGS option.
Common Causes
- An INSERT or UPDATE supplies a value whose length exceeds the column's declared size, such as 50 characters aimed at a VARCHAR(20) column
- An import or migration job feeds text from wider source columns into a shorter target table
- A concatenation or computed expression produces output wider than the destination column
- An UPDATE rewrites a column with combined text whose total length outgrows the declared size
Typical Scenarios
- A user submits a 300-character comment into a form field backed by a VARCHAR(255) column, and the insert is rejected
- An import script loads CSV rows where one text field exceeds the target column's width, stopping the batch on the first oversized value
- A migration copies rows from a legacy table into a staging table with narrower columns and fails on the first row that no longer fits
- An UPDATE combines two columns into one target column and the concatenated result outgrows the declared size
What to Know
Locating the column whose declared size no longer fits the data is the core diagnostic task. Compare the column's defined length with the longest value being written, then either shorten the data at the application boundary or widen the column after checking dependent objects. Because parameters and variables truncate silently, that path deserves a check too when data looks cut but no error appeared.
Frequently Asked Questions
Common questions about SQL Server 8152 error
It can, and the ANSI_WARNINGS setting decides which behavior applies. With ANSI_WARNINGS ON the INSERT or UPDATE is canceled as the ISO standard specifies; with it OFF the data is truncated to the column's size and the statement succeeds. The strict mode is what keeps oversize writes from disappearing quietly.
No. For VARCHAR, n defines the string size in bytes, and with multibyte character sets fewer characters fit than n. For NVARCHAR, n defines the size in byte-pairs, and under UTF-16 supplementary characters take two byte-pairs, so the character count that fits can drop below n.
Enable trace flag 460, or the VERBOSE_TRUNCATION_WARNINGS database-scoped configuration on SQL Server 2019 and later: it replaces 8152 with message 2628, which names the table, the column, and the truncated value. From database compatibility level 150 the detailed message is already the default.
ANSI_WARNINGS is not honored when passing parameters to a stored procedure or function, or when setting variables in a batch: a value larger than the declared size is truncated and the statement succeeds. Oversize data on that path never raises 8152, so inputs need checking before the call.
No. With ANSI_WARNINGS ON the statement is canceled, so no row is written with cut data. The risk sits in the silent paths: with ANSI_WARNINGS OFF, and in conversions to or from binary or varbinary data where no warning or error is issued regardless of SET options, the excess characters are dropped without any signal.
Related Errors From Other Categories
Similar error codes documented across different platforms and systems