Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Primary keys – the basics
Single-column primary keys
Multi-column primary keys
16. Uniqueness with multi-column primary keys – summary
NOT NULL
Review

Instruction

Well, the insertion has failed, because the database keeps track of what is being added. If it finds out that the combination which constitutes the primary key has already been used, your instruction will be rejected.

Exercise

Let's see if you can create a new table based on the description below:

Each customer in our store has certain favorite genres. As such, we need a table named preference consisting of the following information:

  • user_id (an integer).
  • priority (an integer).
  • genre (text of up to 20 characters).

The first two columns form the primary key.

We created a simple template for you. Fill in the gaps with the table name, column names, and column types!

Stuck? Here's a hint!

Type:

CREATE TABLE preference (
   user_id integer,
   priority integer,
   genre varchar(20),
   PRIMARY KEY (user_id, priority)
);