0% found this document useful (0 votes)
36 views2 pages

BCDE103 Keys Class Notes

The document provides an overview of primary keys in relational databases: - A primary key uniquely identifies each record in a database table and consists of one or more columns. It should have as few columns as possible. - Natural/business primary keys are attributes that uniquely identify real-world objects, like company names or vehicle identification numbers. - Surrogate keys are artificially generated unique identifiers needed when there is no natural primary key, like identification numbers for people. - Foreign keys link tables by including the primary key of one table as a column in another table, referencing the other table. They ensure integrity between linked tables.

Uploaded by

elliottjs1091
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views2 pages

BCDE103 Keys Class Notes

The document provides an overview of primary keys in relational databases: - A primary key uniquely identifies each record in a database table and consists of one or more columns. It should have as few columns as possible. - Natural/business primary keys are attributes that uniquely identify real-world objects, like company names or vehicle identification numbers. - Surrogate keys are artificially generated unique identifiers needed when there is no natural primary key, like identification numbers for people. - Foreign keys link tables by including the primary key of one table as a column in another table, referencing the other table. They ensure integrity between linked tables.

Uploaded by

elliottjs1091
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

BCDE103 Keys Lecture Notes

5 March 2023, Chris Bartlett

Introduction

In the previous sessions when talking about how to normalise database tables we referred to the
idea of unique records and attributes that made each record unique. We used unique attributes as
the basis of normalising our tables to 2NF and 3NF. What we were doing in formal database terms
was identifying primary keys, which is the main topic of this session.

Uniquely identifying records: primary keys

A primary key is a set of attributes (columns) that uniquely identifies a record in a database table.
Having unique records in tables is vital for relational databases: no duplication of data.

Note: The primary key should have as few columns as possible.

Natural/Business primary keys


A primary key may consist of data that is an attribute of an object. For example, the name of a car
company is a natural primary key for a table of car companies (assuming no two companies can have
the same name). The term “business key” is also used – facts that the business creates/stores can
also form a primary key. E.g., a vehicle’s VIN; a passport number (identifies a passport, not a
person!). A primary key might be a combination of more than one attribute.

Surrogate keys
If there is no natural primary key for a table, then we need to create one. This is called a surrogate
key. Once we have a surrogate key it functions in the same way as a primary key, as the identifier for
that record.

Quick exercise
What attributes of a person (that aren’t physical like fingerprints) make them unique?

There is nothing that is guaranteed to be unique, but we can’t have a “99.9% solution”. A table for
people is the standard example of when you need a surrogate key (which is usually an ID number).

Quick exercise
What could we use as a surrogate key for people? In the USA the standard one is the Social Security
Number. What could we use in NZ?

The problem with NZ is that not everyone has an IRD number and there would be privacy issues if
that was shared. In practice, we just need to create a unique identifier of our own, such as a serial
number.

1
Foreign keys

In our previous classes we briefly mentioned linking tables together or referencing other tables.
When we put the primary key of one table into a second table to act as a reference, we are adding a
foreign key. It is called “foreign” because it is not native to that table. It might appear that we are
duplicating data, but this is not the case – we will see how database management systems ensure
the integrity of keys in a later session.

Lab

Do the lab work, please!

You might also like