- Error number
- 8152
- Severity
- 16 (user-correctable error)
- State
- 30
- Product
- Microsoft SQL Server Database Engine
- Versions
- All supported SQL Server versions (2016 to 2025), Azure SQL Database and Azure SQL Managed Instance. On SQL Server 2019 and later it appears only at database compatibility level 140 or lower, or with VERBOSE_TRUNCATION_WARNINGS = OFF; otherwise the engine raises 2628.
- Category
- Data Type & Conversion
- Last reviewed
- 23 October 2026
On this page
What it means
Error 8152 means an INSERT or UPDATE tried to store a string or binary value longer than the target column allows, and SQL Server rejected the statement rather than cut the value.
Every char, varchar, nchar, nvarchar, binary and varbinary column has a maximum length. When a write would have to cut a value to fit, SQL Server stops the statement and rolls it back. This short message names no table, column or value, which is what makes it hard: on a wide table you must find which column is too narrow yourself.
On SQL Server 2025 the same write raises the detailed error 2628 whenever the database is at compatibility level 150 or higher and the database scoped configuration VERBOSE_TRUNCATION_WARNINGS is ON (the default). Seeing 8152 on SQL Server 2019 or later therefore tells you the database runs at level 140 or lower, or that someone turned that setting off. Note that assigning a long value to a variable, or CAST to a shorter type, truncates silently with no error at all.
Common causes
- A value longer than the column, for example user input or an imported field that grew past VARCHAR(50).
- An UPDATE that appends text (
code = code + '...') and pushes existing values over the limit. - INSERT ... SELECT from a source with wider columns than the target, such as a staging table typed NVARCHAR(MAX).
- Unicode or binary data whose length was sized for a different type or encoding.
Diagnose it
Read-only These queries only read metadata and dynamic management views. They do not change data, permissions or configuration, so they are safe to run first.
Check why the database reports 8152 and not 2628
SELECT d.name, d.compatibility_level,
(SELECT CAST(value AS int) FROM sys.database_scoped_configurations
WHERE name = N'VERBOSE_TRUNCATION_WARNINGS') AS verbose_truncation_warnings
FROM sys.databases AS d
WHERE d.name = DB_NAME(); A compatibility level of 140 or lower, or verbose_truncation_warnings = 0, explains the short message. Level 150 or higher with 1 should give 2628.
List the target column sizes
max_length is in bytes: an nvarchar column holds half as many characters, and -1 means MAX.
SELECT c.name AS column_name, TYPE_NAME(c.user_type_id) AS data_type, c.max_length
FROM sys.columns AS c
WHERE c.object_id = OBJECT_ID(N'dbo.Users')
AND TYPE_NAME(c.user_type_id) IN ('char','varchar','nchar','nvarchar','binary','varbinary')
ORDER BY c.column_id; The width of every string and binary column the write touches.
Find the source rows that are too long
SELECT id, code, LEN(code) AS len
FROM staging.Users
WHERE LEN(code) > 50
ORDER BY len DESC; Every row that would fail. Repeat for each candidate column, comparing LEN (characters) or DATALENGTH (bytes) with the target width.
How to fix it
Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.
Get the detailed 2628 message
Changes configurationOn SQL Server 2019 and later, turn VERBOSE_TRUNCATION_WARNINGS back on, or raise the database compatibility level to 150 or higher, and rerun the failing statement to see the table, column and value. On SQL Server 2016 SP2 CU6 and 2017 CU12 and later builds, Microsoft documents trace flag 460 for the same purpose.
Caution:
Changing the compatibility level also changes query optimiser behaviour and can change plans. Test the workload at the new level first. Enabling a trace flag globally affects the whole instance.
ALTER DATABASE SCOPED CONFIGURATION SET VERBOSE_TRUNCATION_WARNINGS = ON;
-- or, after testing the application at the new level
ALTER DATABASE CURRENT SET COMPATIBILITY_LEVEL = 150;
Widen the column
Changes schemaIf the longer values are legitimate, enlarge the column to the real maximum length of the data.
Caution:
Restate NULL or NOT NULL when you alter the column, otherwise it may change. Columns used by indexes or constraints may need those dropped first.
ALTER TABLE dbo.Users
ALTER COLUMN code VARCHAR(100);
Validate or shorten the input before writing
Changes dataIf the column size is right, reject over-long values, or cut them deliberately with LEFT when losing the tail is acceptable.
INSERT INTO dbo.Users (code)
SELECT LEFT(code, 50)
FROM staging.Users;
Examples
Inserting a value longer than the column
-- At level 140 or lower the short 8152 message is used
ALTER DATABASE CURRENT SET COMPATIBILITY_LEVEL = 140;
GO
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 8 String or binary data would be truncated. The statement has been terminated.
Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.
An UPDATE that overflows the column
ALTER DATABASE CURRENT SET COMPATIBILITY_LEVEL = 140;
GO
CREATE TABLE dbo.Users (
id INT IDENTITY(1,1) PRIMARY KEY,
code VARCHAR(50)
);
INSERT INTO dbo.Users (code) VALUES ('ORDER-2026-000123');
-- 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 9 String or binary data would be truncated. The statement has been terminated.
Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.
At a current level, with verbose truncation warnings turned off
The database stays at its default level (170 on SQL Server 2025). With VERBOSE_TRUNCATION_WARNINGS ON, the same insert raises error 2628 instead.
ALTER DATABASE SCOPED CONFIGURATION SET VERBOSE_TRUNCATION_WARNINGS = OFF;
GO
CREATE TABLE dbo.Users (
id INT IDENTITY(1,1) PRIMARY KEY,
code VARCHAR(50)
);
INSERT INTO dbo.Users (code)
VALUES ('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
Msg 8152, Level 16, State 30, Line 7 String or binary data would be truncated. The statement has been terminated.
Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.
How to prevent it
Size columns from the real data and enforce the same maximum length in the application, so over-long values are rejected with a clear message before they reach the database. Check staging data with LEN before loading it.
Keep databases at compatibility level 150 or higher with VERBOSE_TRUNCATION_WARNINGS ON where the application allows it, so any truncation that slips through names its column. For choosing string widths, see SQL data types explained.
Common questions
Why does error 8152 not tell me which column is too small?
8152 is the original message, which carries no details. The detailed version is a separate error, 2628. You get 8152 on SQL Server 2019 and later only when the database is at compatibility level 140 or lower or VERBOSE_TRUNCATION_WARNINGS is OFF.
I am on SQL Server 2022 or 2025. Why do I still see 8152?
Check the database, not the server: a database restored or upgraded from an older version often keeps its old compatibility level, such as 130 or 140. Raise it after testing, or look at sys.database_scoped_configurations for VERBOSE_TRUNCATION_WARNINGS = 0.
Why does SET @v = a long string not raise 8152?
Assignments to variables and CAST or CONVERT to a shorter type truncate silently. On SQL Server 2025, DECLARE @v varchar(5) = 'abcdefgh' stores abcde with no error. Only writes to table columns raise 8152 or 2628.
Learn more on CodeWithSQL
Official documentation
- ALTER DATABASE SCOPED CONFIGURATION: VERBOSE_TRUNCATION_WARNINGS
- ALTER DATABASE compatibility level (Transact-SQL)
- Trace flags (trace flag 460)
Last technically reviewed 23 October 2026; examples and diagnostics run on SQL Server 2025 (17.0.1145.4). Message text checked against the engine's sys.messages catalogue.