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
12. Removing a UNIQUE constraint
Summary

Instruction

Excellent work! Now, let's try to do the opposite: delete a constraint from an existing table. Here's the table:

CREATE TABLE group_game (
  id integer PRIMARY KEY,
  name varchar(64) UNIQUE,
  min_players integer,
  max_players integer
);

There's a UNIQUE constraint on the name column. To remove it, we can use this code:

ALTER TABLE group_game
DROP CONSTRAINT group_game_name_key;

How do we know the name of the constraint? PostgreSQL's naming convention for UNIQUE is table_name + _ + constraint_column(s) + _ + key. That's why our constraint was named group_game_name_key.

Exercise

After the previous exercise, we've got the new UNIQUE constraint in our table card_game:

CREATE TABLE card_game (
  id integer PRIMARY KEY,
  name varchar(64) UNIQUE,
  card_game_rank integer UNIQUE
);

However, you now need to get rid of the UNIQUE constraint on the name column.