T-SQL Tutorial

Msg 515 Level 16 - Cannot insert the value NULL into column


On Transact SQL language the Msg 515 Level 16 - Cannot insert the value NULL into column means that the column does not allow nulls and the insert fails.

Msg 515 Level 16 Example:

We have the table teachers:

USE model;
GO
CREATE TABLE teachers(
   ID INT IDENTITY NOT NULL PRIMARY KEY,
   Name VARCHAR(250) NOT NULL,
   Department VARCHAR(250) NOT NULL);
GO

Invalid insert:

USE model;
GO
INSERT INTO teachers(id, name, department)
VALUES ('Olivia Wilson', null), ('Ethan Davis', null);
GO

Message
Msg 515, Level 16, State 2, Line 1
Cannot insert the value NULL into column 'Department', table 'model.dbo.teachers'; column does not allow nulls. INSERT fails. The statement has been terminated.

Correct insert:

USE model;
GO
INSERT INTO teachers(name, department)
VALUES ('Olivia Wilson', 'Anthropology'), ('Ethan Davis', 'Biology');
GO

Message
(2 row(s) affected)

Other error messages: