On this page
Why it happens
Error 8152 means the value you are writing is longer than the column can hold. For example, a 60 character string will not fit into a VARCHAR(50) column, so rather than silently chop off the extra characters SQL Server rejects the whole statement and rolls it back. The severity is 16, a normal data error you can catch and correct.
The classic 8152 message is famously frustrating because it does NOT name the column, the row, or the value that overflowed. On a wide table with many string columns you are left guessing which one is too small, which is why so many people search for this exact error.
SQL Server 2019 replaced this message with the much clearer error 2628, which names the table, the column, and the truncated value. On SQL Server 2017 and 2019 you can turn on that better message with trace flag 460 or by raising the database compatibility level to 150 or higher.
Examples
Inserting a value longer than the column
CREATE TABLE dbo.Users (
id INT IDENTITY(1,1) PRIMARY KEY,
code VARCHAR(50)
);
-- This string is 60 characters, the column holds 50
INSERT INTO dbo.Users (code)
VALUES ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
Msg 8152, Level 16, State 30, Line 7 String or binary data would be truncated.
An UPDATE that overflows the column
-- Appending text pushes the value past VARCHAR(50)
UPDATE dbo.Users
SET code = code + '-EXTRA-SUFFIX-THAT-MAKES-IT-TOO-LONG'
WHERE id = 1;
Msg 8152, Level 16, State 30, Line 2 String or binary data would be truncated.
The clearer 2628 message on SQL Server 2019 and later
-- Same insert on SQL Server 2019+ reports which column overflowed
INSERT INTO dbo.Users (code)
VALUES ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
Msg 2628, Level 16, State 1, Line 2 String or binary data would be truncated in table 'db.dbo.Users', column 'code'. Truncated value: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'.
How to fix it
Find the offending column and row by comparing lengths
Because 8152 will not tell you which column is too small, compare the LEN() or DATALENGTH of each candidate value against the column size. Any row where the length exceeds the column width is a culprit.
-- Compare value length to the column width (50)
SELECT id, code, LEN(code) AS len
FROM staging.Users
WHERE LEN(code) > 50
ORDER BY len DESC;
Widen the column with ALTER TABLE
If the data legitimately needs more room, enlarge the column so the value fits. Choose a size that covers the real maximum length of your data.
ALTER TABLE dbo.Users
ALTER COLUMN code VARCHAR(100);
Shorten and validate the input before inserting
If the column size is correct and the data is simply too long, trim or reject the value before writing it. Validate the length so you never send more than the column can hold.
-- Keep only the first 50 characters that fit
INSERT INTO dbo.Users (code)
SELECT LEFT(code, 50)
FROM staging.Users;
Turn on the clearer 2628 message
On SQL Server 2017 and 2019, enable the better error that names the column. Use trace flag 460 for the session, or raise the database compatibility level to 150 or higher so 2628 becomes the default.
-- Option A: enable the better message for this session
DBCC TRACEON(460);
-- Option B: raise the database compatibility level (150 = SQL Server 2019)
ALTER DATABASE CURRENT SET COMPATIBILITY_LEVEL = 150;
How to prevent it
Size columns to the real data. Measure the longest values you expect and pick a width that comfortably holds them, rather than defaulting every text column to a tiny fixed size. For a refresher on choosing widths, see SQL data types explained.
Validate input length in the application before it reaches the database. Enforce the same maximum length in your forms, models, and API layer as the column defines, so overlong values are caught early with a clear message instead of a generic 8152 at insert time. Use LEN() checks on imported data before loading it.
Common questions
How do I fix SQL Server error 8152?
Find the column whose width is smaller than the value you are inserting. Compare LEN() of each string value to the column size to locate it, then either widen the column with ALTER TABLE ... ALTER COLUMN or shorten and validate the input before inserting. On SQL Server 2019 and later, error 2628 names the offending column for you.
Why does error 8152 not tell me which column overflowed?
The classic 8152 message was written before SQL Server tracked which column caused the truncation, so it only says the data would be truncated. SQL Server 2019 replaced it with error 2628, which names the table, column, and truncated value. On SQL Server 2017 or 2019 you can enable that clearer message with trace flag 460 or compatibility level 150.
What is the difference between error 8152 and error 2628?
They describe the same problem: a string or binary value too long for its column. Error 8152 is the old generic message that names nothing, while error 2628 is the newer replacement that names the table, column, and truncated value so you can fix it immediately.