Sleutels en supersleutels

Introductie tot relationele databases in SQL

Timo Grossenbacher

Data Journalist

Het huidige databasemodel

Introductie tot relationele databases in SQL

Het databasemodel met primaire sleutels

Introductie tot relationele databases in SQL

Wat is een sleutel?

  • Attribuut/attributen die een record uniek identificeren
  • Zolang je attributen kunt verwijderen: supersleutel
  • Als er niets meer weg kan: minimale supersleutel of sleutel
Introductie tot relationele 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

Aangepast van Elmasri, Navathe (2011): Fundamentals of Database Systems, 6e ed., Pearson

Introductie tot relationele 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 t/m 3 bestaan uit één attribuut
  • Verwijder je "make" of "year" uit K4, dan ontstaan duplicaten
  • Slechts één kandidaat-sleutel kan de gekozen sleutel zijn
Introductie tot relationele databases in SQL

Laten we sleutels ontdekken!

Introductie tot relationele databases in SQL

Preparing Video For Download...