- Error number
- 515
- Severity
- 16 (user-correctable error)
- State
- 2
- Product
- Microsoft SQL Server Database Engine
- Versions
- All supported SQL Server versions (2016 to 2025), Azure SQL Database, Azure SQL Managed Instance
- Category
- Constraint & Integrity
- Last reviewed
- 23 October 2026
On this page
What it means
Error 515 means a statement tried to leave NULL in a column declared NOT NULL, usually because no value was supplied and the column has no default.
The message tells you exactly where to look: the column name, then the table as database.schema.table, then the kind of statement that failed (INSERT fails or UPDATE fails). SQL Server checks NOT NULL for every row before it stores anything, so the whole statement is rolled back, including the rows that were fine.
An omitted column gets its DEFAULT, and when there is no DEFAULT it gets NULL, which a NOT NULL column refuses. Severity 16 is a normal, catchable error. The last word is not always the statement you typed: ALTER TABLE ... ALTER COLUMN ... NOT NULL over rows that hold NULL, and a MERGE that inserts NULL, both report UPDATE fails on SQL Server 2025. Adding a new NOT NULL column without a default to a table with rows is a different error, 4901.
Common causes
- An INSERT leaves out a required column that has no DEFAULT constraint.
- A variable or parameter that was never set (still NULL) is passed into a NOT NULL column.
- An INSERT ... SELECT, MERGE or import brings NULLs from the source, often from an outer join or an unmapped column.
- An UPDATE sets a NOT NULL column to NULL, sometimes through a subquery that found no row.
- ALTER COLUMN tries to make a column NOT NULL while some rows still hold NULL.
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.
Which columns are required, and which have a default?
SELECT c.name AS column_name, TYPE_NAME(c.user_type_id) AS data_type, c.is_nullable,
c.is_identity, c.is_computed, dc.definition AS default_definition
FROM sys.columns AS c
LEFT JOIN sys.default_constraints AS dc
ON dc.parent_object_id = c.object_id AND dc.parent_column_id = c.column_id
WHERE c.object_id = OBJECT_ID(N'dbo.Customers')
ORDER BY c.column_id; Columns with is_nullable = 0, no identity and no default_definition must be given a value by every INSERT.
Find the source rows that would bring a NULL
SELECT *
FROM dbo.StagingCustomers
WHERE email IS NULL; Rows returned are the ones an INSERT ... SELECT would reject. Fix them, give them a fallback or leave them out.
Before ALTER COLUMN ... NOT NULL: count the existing NULLs
SELECT COUNT(*) AS null_rows
FROM dbo.Customers
WHERE email IS NULL; Anything above 0 makes the ALTER COLUMN fail with 515. Fill those rows first.
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.
Supply the value
Changes dataWhen the column is genuinely required, list it in the INSERT and make sure the variable or parameter feeding it is set. Validate required fields in the application before the call.
INSERT INTO dbo.Customers (id, name, email)
VALUES (1, N'Sara', N'sara@example.com');
Give the column a DEFAULT
Changes schemaWhen there is a sensible fallback (a timestamp, a status, zero), a DEFAULT constraint fills it whenever the column is left out. A default is not used when the statement passes NULL explicitly.
ALTER TABLE dbo.Customers
ADD CONSTRAINT DF_Customers_status DEFAULT ('active') FOR status;
Replace NULLs in the source
Changes dataFor an INSERT ... SELECT, substitute a value with COALESCE, or filter the rows out and handle them separately. Agree the fallback with whoever owns the data.
INSERT INTO dbo.Customers (id, name, email)
SELECT id, name, COALESCE(email, N'unknown@example.com')
FROM dbo.StagingCustomers;
Fill existing NULLs before making a column NOT NULL
Changes dataFor the ALTER COLUMN case, update the NULL rows first, then change the column. On a large table, update in batches to keep the transaction log and locking under control.
UPDATE dbo.Customers SET email = N'unknown@example.com' WHERE email IS NULL;
ALTER TABLE dbo.Customers ALTER COLUMN email NVARCHAR(255) NOT NULL;
Allow NULL, only if the value is truly optional
Changes schemaIf the business rule says the value can be unknown, make the column nullable. Do not do this just to get past the error: queries and reports that assume a value will then have to handle NULL. See NULL values explained.
ALTER TABLE dbo.Customers ALTER COLUMN phone VARCHAR(20) NULL;
Examples
An INSERT that leaves out a required column
CREATE TABLE dbo.Customers (
id INT PRIMARY KEY,
name NVARCHAR(100) NOT NULL,
email NVARCHAR(255) NOT NULL
);
INSERT INTO dbo.Customers (id, name) VALUES (1, N'Sara'); -- email has no default
Msg 515, Level 16, State 2, Line 7 Cannot insert the value NULL into column 'email', table 'AppDb.dbo.Customers'; column does not allow nulls. INSERT fails. The statement has been terminated.
Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.
INSERT ... SELECT from a source with a missing value
CREATE TABLE dbo.Customers (
id INT PRIMARY KEY,
name NVARCHAR(100) NOT NULL,
email NVARCHAR(255) NOT NULL
);
CREATE TABLE dbo.StagingCustomers (id INT, name NVARCHAR(100), email NVARCHAR(255));
INSERT INTO dbo.StagingCustomers VALUES (1, N'Sara', N'sara@example.com'), (2, N'Ali', NULL);
INSERT INTO dbo.Customers (id, name, email)
SELECT id, name, email FROM dbo.StagingCustomers; -- row 2 has no email, nothing is loaded
Msg 515, Level 16, State 2, Line 9 Cannot insert the value NULL into column 'email', table 'AppDb.dbo.Customers'; column does not allow nulls. INSERT fails. The statement has been terminated.
Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.
An UPDATE that clears a required column
CREATE TABLE dbo.Customers (
id INT PRIMARY KEY,
name NVARCHAR(100) NOT NULL,
email NVARCHAR(255) NOT NULL
);
INSERT INTO dbo.Customers VALUES (1, N'Sara', N'sara@example.com');
DECLARE @new_email NVARCHAR(255); -- never assigned, so NULL
UPDATE dbo.Customers SET email = @new_email WHERE id = 1;
Msg 515, Level 16, State 2, Line 9 Cannot insert the value NULL into column 'email', table 'AppDb.dbo.Customers'; column does not allow nulls. UPDATE fails. The statement has been terminated.
Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.
How to prevent it
Give required columns a DEFAULT wherever a sensible one exists, and list columns explicitly in every INSERT so a missing one is visible in code review. Check parameters for NULL at the start of stored procedures and fail with a clear message of your own.
Profile staging data for NULLs before loading it, and before tightening a column to NOT NULL. Treat outer joins in INSERT ... SELECT with care: an unmatched row produces NULL in every column from the other side. See the constraints guide.
Common questions
Why do I get error 515 when I never mentioned that column?
A column left out of an INSERT receives its DEFAULT, and NULL when it has none. Add the column to the INSERT or give it a DEFAULT constraint.
Why does the message say UPDATE fails when I ran ALTER TABLE or MERGE?
SQL Server reports the internal operation. Making a column NOT NULL over existing NULL rows, and a MERGE inserting NULL, both said UPDATE fails in our SQL Server 2025 tests. The fix is the same: remove the NULLs first.
Does a DEFAULT help when I pass NULL explicitly?
No. A default is used only when the column is omitted or you write DEFAULT. An explicit NULL, or a NULL variable, still raises 515.
Learn more on CodeWithSQL
Official documentation
- Specify default values for columns (Microsoft Learn)
- CREATE TABLE (Transact-SQL)
- Database Engine events and errors 0 to 999
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.