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

Instruction

Okay, have you noticed the new element in the code? You should be familiar with the instruction:

CREATE TABLE movie (
   id integer PRIMARY KEY,
   name varchar(64),
   year integer
);

It will create a table called movie with the columns specified in the parentheses. There, we provide column names with their types. However, after the part id integer, we insert the following piece of information:

PRIMARY KEY

During this part of the course, we're going to examine primary keys closely. What are they exactly? Well, a primary key is a set of columns which is used to identify a given row in the table. Sounds too vague? Don't worry, we're going to explain it to you soon!

Exercise

We've inserted some information into the movie table. Take a close look at the contents of the table.

In particular, examine the column id which is the primary key. Each ID is unique: the same number only appears once.

Apart from that, we do not have an ID of 7. That's because primary keys, if not specified, do not need to follow any specific order. If the number 7 is missing, nothing particularly happens.