Nullable columns in tables
suggest changeWhen creating tables it is possible to declare a column as nullable or non-nullable.
CREATE TABLE MyTable
(
MyCol1 INT NOT NULL, -- non-nullable
MyCol2 INT NULL -- nullable
) ;
If you omit both NULL and NOT NULL, nullability is implementation-defined. A primary-key column is not nullable. The statements below set nullability explicitly.
Attempting to assign NULL to a non-nullable column will result in an error.
INSERT INTO MyTable (MyCol1, MyCol2) VALUES (1, NULL) ; -- works fine
INSERT INTO MyTable (MyCol1, MyCol2) VALUES (NULL, 2) ;
-- cannot insert
-- the value NULL into column 'MyCol1', table 'MyTable';
-- column does not allow nulls. INSERT fails.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents