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
11. Adding a UNIQUE constraint with a custom name
Summary

Instruction

Good job! Just like with primary and foreign key constraints, you can also add a custom name to your UNIQUE constraints. Check out this table:

CREATE TABLE video_game (
  id integer PRIMARY KEY,
  name varchar(64),
  platform varchar(64),
  price decimal(6, 2)
);

You can add a constraint like this:

ALTER TABLE video_game
ADD CONSTRAINT video_game_unique UNIQUE (name, platform);

The instruction above will create a new unique constraint and name it video_game_unique.

Exercise

Again, we've got the table named card_game defined like this:

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

Add a UNIQUE constraint on the rank column. This time, however, provide the custom constraint name card_game_rank_unique.