Keys and superkeys

Introduction to Relational Databases in SQL

Timo Grossenbacher

Data Journalist

The current database model

Introduction to Relational Databases in SQL

The database model with primary keys

Introduction to Relational Databases in SQL

What is a key?

  • Attribute(s) that identify a record uniquely
  • As long as attributes can be removed: superkey
  • If no more attributes can be removed: minimal superkey or key
Introduction to Relational Databases in SQL
     license_no     | serial_no |    make    |  model  | year
 -------------------+-----------+------------+---------+------
 Texas ABC-739      | A69352    | Ford       | Mustang |    2
 Florida TVP-347    | B43696    | Oldsmobile | Cutlass |    5
 New York MPO-22    | X83554    | Oldsmobile | Delta   |    1
 California 432-TFY | C43742    | Mercedes   | 190-D   |   99
 California RSK-629 | Y82935    | Toyota     | Camry   |    4
 Texas RSK-629      | U028365   | Jaguar     | XJS     |    4

SK1 = {license_no, serial_no, make, model, year}

SK2 = {license_no, serial_no, make, model}

SK3 = {make, model, year}, SK4 = {license_no, serial_no}, SKi, ..., SKn

Adapted from Elmasri, Navathe (2011): Fundamentals of Database Systems, 6th Ed., Pearson

Introduction to Relational Databases in SQL
     license_no     | serial_no |    make    |  model  | year
 -------------------+-----------+------------+---------+------
 Texas ABC-739      | A69352    | Ford       | Mustang |    2
 Florida TVP-347    | B43696    | Oldsmobile | Cutlass |    5
 New York MPO-22    | X83554    | Oldsmobile | Delta   |    1
 California 432-TFY | C43742    | Mercedes   | 190-D   |   99
 California RSK-629 | Y82935    | Toyota     | Camry   |    4
 Texas RSK-629      | U028365   | Jaguar     | XJS     |    4

K1 = {license_no}; K2 = {serial_no}; K3 = {model}; K4 = {make, year}

  • K1 to 3 only consist of one attribute
  • Removing either "make" or "year" from K4 would result in duplicates
  • Only one candidate key can be the chosen key
Introduction to Relational Databases in SQL

Let's discover some keys!

Introduction to Relational Databases in SQL

Preparing Video For Download...