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
23. NULL or NOT NULL?
Review

Instruction

All right! So, overall, is it better to create columns with or without NULLs? Well, the rule of thumb is that we shouldn't create NULLable columns unless it's necessary to do so, since, generally speaking, it's more difficult to create queries with columns that can contain NULL values.

Exercise

Game lovers have suggested we add a few columns to the rpg_game table.

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 they'd like to see 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 anticipated one. However, some games do not have expansions, so the column should be left empty for those.

Based on the suggestions above, complete the template with two columns. Put a NULL or NOT NULL constraint after the type of the column.

Stuck? Here's a hint!

Type:

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