Introduction
UNIQUE
NOT NULL
16. NULL or NOT NULL?
CHECK
DEFAULT
Summary

Instruction

Alright! So, to sum up, you may wonder whether it's generally better to create columns with or without NULLs. Well, the rule of thumb is that we shouldn't create NULLable columns when it's not necessary because generally speaking it’s more difficult to create queries with columns which can contain NULL values.

Exercise

The game lovers suggested we add a few columns to the table rpg_game.

Most of them say we should add a column races_no which will provide the user with the number of races available in each game (an integer value). The users agree that this column should be obligatory for each game.

Another column which should be added is called expansion. This column of up to 32 characters should provide the name of the first expansion of the RPG game, which is always the most awaited one. However, some games do not have expansions, so the column should be left empty.

Based on the description above, complete the template with two columns. Each time put a NULL or NOT NULL constraint after the type of the column.

Stuck? Here's a hint!

Type

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

Console

Code editor

Result

TableConsole