SQL Server Error 515: Cannot Insert NULL into a NOT NULL Column
Diagnose SQL Server Msg 515 by checking the named NOT NULL column, supplied values, omitted columns, and default constraints.
On this page
SQL Server Msg 515 means an INSERT or UPDATE tried to store NULL in a column that does not allow it. The error message identifies the column and table. Check whether the statement supplied NULL, omitted a required column with no default, or produced a NULL from an expression before changing the schema.
Find the required column and its default
The error message names the column that rejected NULL. Inspect its nullability and any default constraint in the same database:
SELECT c.name,
c.is_nullable,
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.Users');
Replace dbo.Users with the table named in the error. Then inspect the INSERT or UPDATE values and any expressions or source columns feeding the required field.
Distinguish an omitted value from an explicit NULL
When an INSERT omits a column, SQL Server uses that column’s default if one exists. Without a default, a NOT NULL column must receive a value. An explicitly supplied NULL does not invoke a default; use the DEFAULT keyword to request the defined default value.
For example, this table gives Status a default:
CREATE TABLE dbo.Tasks (
TaskID int IDENTITY PRIMARY KEY,
Name nvarchar(100) NOT NULL,
Status varchar(20) NOT NULL
CONSTRAINT DF_Tasks_Status DEFAULT ('Pending')
);
Omitting Status uses the default:
INSERT INTO dbo.Tasks (Name)
VALUES (N'Prepare report');
To ask SQL Server to use the default explicitly, use the DEFAULT keyword:
INSERT INTO dbo.Tasks (Name, Status)
VALUES (N'Prepare report', DEFAULT);
By contrast, explicitly supplying NULL still raises Msg 515, even though the column has a default:
INSERT INTO dbo.Tasks (Name, Status)
VALUES (N'Prepare report', NULL);
See Microsoft’s INSERT documentation and default constraint guidance.
Choose a valid fix
- Supply a meaningful non-
NULLvalue when the field is required by the data model. - Omit the column or use
DEFAULTonly when the defined default is correct for this row. - Change the column to allow
NULLonly if the application and data model genuinely permit a missing value. - When adding
NOT NULLto an existing table, find and backfill existingNULLrows before changing the column definition.
Avoid inserting a placeholder merely to suppress the error. For other SQL Server errors, see the SQL Server error troubleshooting index.