Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Primary keys – the basics
Single-column primary keys
Multi-column primary keys
NOT NULL
22. NULL columns
Review

Instruction

And... success! We did not specify that the columns were NOT NULL, so we could leave them without a value. In other words, if a column doesn't have the NOT NULL constraint, its value can be a NULL.

If you want, you can stress the fact that a certain column can be NULL by writing the keyword NULL after the column type:

CREATE TABLE rpg_game (
    id int PRIMARY KEY,
    name varchar(32) NULL,
    genre varchar(32),
    classes_no integer,
    complexity integer,
    min_players integer
);

The above code would work just as well without the NULL keyword. Its point is to draw the reader's attention to the fact that a column is NULLable.

Exercise

We've added the keyword NULL to every column in the rpg_game table except for the id column. Go ahead and try to add a few rows without some of the NULLable columns. Observe what happens.