Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Primary keys – the basics
Single-column primary keys
9. Primary key data type
Multi-column primary keys
NOT NULL
Review

Instruction

Excellent! Now, you may be wondering if the primary key must always be an integer column. The answer is no. You can choose other column types as well. For instance, you could de-emphasize the id column in our movie table and instead use the title of the movie as the primary key.

Are these types of solutions popular? Well, not really. Such a primary key will work more slowly and is more difficult to handle.

Exercise

Let's experiment. Create the movie table without the id column. Insert the following columns:

  • title – a field of up to 64 characters and the primary key.
  • year – an integer.
  • genre – a field of up to 10 characters.

Stuck? Here's a hint!

Type:

CREATE TABLE movie (
   title varchar(64) PRIMARY KEY,
   year integer,
   genre varchar(10)
);