Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Defining columns with UNIQUE
Adding and removing UNIQUE constraints
Summary
13. Summary

Instruction

Okay, time to wrap things up! What did we learn?

  1. You can add a UNIQUE constraint to a single column, placing it after the column type:
    CREATE TABLE board_game (
      id integer PRIMARY KEY,
      name varchar(32) UNIQUE
    );
  2. You can add a UNIQUE constraint to a group of columns, placing it after the column definitions:
    CREATE TABLE board_game (
      id integer PRIMARY KEY,
      name varchar(32),
      genre varchar(32),
      UNIQUE (name, genre)
    );
  3. You can add a UNIQUE constraint to an existing table:
    ALTER TABLE video_game
    ADD CONSTRAINT video_game_unique UNIQUE (name, platform);
  4. You can remove a UNIQUE constraint from an existing table:
    ALTER TABLE group_game
    DROP CONSTRAINT group_game_name_key;

How about a quick quiz now?

Exercise

Click Next exercise to continue.