Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Primary keys - the basics
Single-column primary keys
Multicolumn primary keys
16. Uniqueness with multicolumn primary keys - summary
Auto-increment columns and sequences


Well, the insertion 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.


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

Each customer in our store has certain favorite genres. This is why we need a table named preference with the following information: user_id (an integer), priority (an integer), genre (text 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!


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