Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Defining columns with DEFAULT
Adding DEFAULT to existing tables
9. Adding a default value for an existing column
Summary

Instruction

Very well done! Now, let's take a look at how we can add a DEFAULT constraint to an existing table. The table looks like this:

CREATE TABLE therapist (
  id integer PRIMARY KEY,
  full_name varchar(32) DEFAULT 'anonymous',
  price decimal(5, 2),
  location varchar(32) DEFAULT 'unknown'
);

We want to add a default value for the price column. To do so, we can write:

ALTER TABLE therapist
ALTER COLUMN price SET DEFAULT 60.00;

The code above will add a default value of 60.00 to the price column in the therapist table.

Exercise

A furniture store has the following table to keep track of the desks they offer:

CREATE TABLE desk (
  id integer PRIMARY KEY,
  model_name varchar(32),
  price decimal(6, 2) DEFAULT 304.91,
  is_customizable boolean
);

Your task is to add a default value of FALSE to the is_customizable column.