Primary Keys

In JOIN, we stated that the flight_id field in the flights table was a primary key...

JOIN ON boarding_passes.flight_id = flights.flight_id;

...what's this mean exactly?

A primary key (PK) uniquely identifies each record in a table.

They're like a Social Security Number!

Confused? Consider this: every U.S. citizen must have a unique Social Security Number to identify themselves and no one else. Therefore, a Social Security Number to a U.S. citizen is the equivalent of a primary key to a record.

If some U.S. citizens had the same Social Security Number, we wouldn't be able to uniquely identify them. This would be a huge issue.

In the same way, if we can't unique identify each record in a table, then we'd run into problems. This is why every record must have a primary key.

How to identify in schema

You can typically identify primary keys within a given table if they have a "PK" next to them.

In the case of the flights table, we can easily see its primary key is the flight_id field.

The reason that flights.flight_id is the primary key of the flights table is because each flight must be able to be uniquely identified. If they aren't, then no one would know which flight a given flight ID is actually referring to, and might go to the wrong boarding gate!

For some extra practice, we can identify the primary key of the boarding_passes table. It's the id field... because each boarding pass must be able to be uniquely identified. If they aren't, then multiple people could use the same boarding pass!

Activate AutoScroll

You haven't unlocked all of BUS 104 yet...

Unlock our 42 concept breakdowns & 10 practice problems with guided solution walkthroughs!