0

I'm trying to add a NOT NULL constraint to my table but it gives me this error:

Cannot insert the value NULL into column 'level_id', table 'project1.oc.courses'; column does not allow nulls. UPDATE fails. The statement has been terminated.

I also tried to insert a NULL value into level_id and it's possible. Any idea why do I get this error then?

CREATE TABLE oc.courses (
    course_id INT PRIMARY KEY IDENTITY (1,1),
    name VARCHAR(255) NOT NULL,
    level_id INT,
    language_id INT,
    series_id INT,
    FOREIGN KEY (series_id) REFERENCES oc.series(series_id),
    FOREIGN KEY (level_id) REFERENCES oc.level(level_id),
    FOREIGN KEY (language_id) REFERENCES oc.language(language_id)
);

ALTER TABLE oc.courses
ALTER COLUMN level_id INT NOT NULL;

0 Answers0