Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
UNIQUE
NOT NULL
CHECK
DEFAULT
26. DEFAULT - Introduction
Summary

Instruction

Excellent, it's time for the last constraint - and for the last type of game on our website - card games! The constraint, in turn, is called DEFAULT. Take a look at the example:

CREATE TABLE card_game (
  id IDENTITY PRIMARY KEY,
  name varchar(32) UNIQUE NOT NULL,
  genre varchar(32),
  min_players int DEFAULT 2,
  min_time int DEFAULT 60,
  cooperation boolean DEFAULT FALSE
);

In the example above, there are a few instances of DEFAULT. Let's take a look at one of them:

min_players DEFAULT 2
As you might expect, the constraint tells the database what the default value should be. In other words, if the user does not provide any value for the given column, it will take the default value instead.

Exercise

Run the template from the example. We're going to work with the new table card_game.