Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Defining columns with DEFAULT
2. DEFAULT – Introduction
Adding DEFAULT to existing tables
Summary

Instruction

Let's get started! Take a look at the example:

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

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

min_players integer DEFAULT 2

As you might expect, the constraint tells the database what the default value should be. In this case, if the user does not provide any value for the the min_players column, the database will insert the default value 2.

Exercise

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