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
18. NOT NULL – Adding NULL values
Review

Instruction

Great. Now that we understand primary keys, let's move on to discussing columns marked with NOT NULL.

Set aside the tables we used previously and switch to tables that could be applied in the gaming industry. Take a look at the following example:

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

The table above provides basic information about a role-playing game. As you may have noticed, we've added a new keyword NOT NULL after the type of the column. Its meaning should be quite clear: the value in the specific column cannot be a NULL. In other words, we must provide a value in this column for each row. NOT NULL is a so-called constraint – that is, a rule that we can apply on a column.

Exercise

Try to add a new RPG game to the table without specifying the name of the game. What do you think will happen?