Home > Articles > Data

Keys in Relational Databases

  • Print
  • + Share This
  • 💬 Discuss
Discover the importance, type, and function of keys as they relate to your work. You will also learn the relationship of keys to various tables and which keys should be used with those tables.

A more recent version of this chapter is available here.

This chapter is from the book

A fact in itself is nothing. It is valuable only for the idea attached to it, or for the proof which it furnishes.
—Claude Bernard

Topics Covered in This Chapter

Why Keys Are Important
Establishing Keys for Each Table
Table-Level Integrity
Reviewing the Initial Table Structures
Case Study
Review Questions

By now you've identified all the subjects that the database will track and defined the table structures that will represent those subjects. Furthermore, you've put the structures through a screening process to control their makeup and quality. In this next stage of the database-design process, you'll begin the task of assigning keys to each table. You'll soon learn that there are different types of keys, and each plays a particular role within the database structure. All but one key is assigned during this stage; you'll assign the remaining key later (in Chapter 10) as you establish relationships between tables.

Why Keys Are Important

Keys are crucial to a table structure for the following reasons:

  • They ensure that each record in a table is precisely identified. As you already know, a table represents a singular collection of similar objects or events. (For example, a CLASSES table represents a collection of classes, not just a single class.) The complete set of records within the table constitutes the collection, and each record represents a unique instance of the table's subject within that collection. You must have some means of accurately identifying each instance, and a key is the device that allows you to do so.

  • They help establish and enforce various types of integrity. Keys are a major component of table-level integrity and relationship-level integrity. For instance, they enable you to ensure that a table has unique records and that the fields you use to establish a relationship between a pair of tables always contain matching values.

  • They serve to establish table relationships. As you'll learn in Chapter 10, you'll use keys to establish a relationship between a pair of tables.

Always make certain that you define the appropriate keys for each table. Doing so will help you guarantee that the table structures are sound, that redundant data within each table is minimal, and that the relationships between tables are solid.

  • + Share This
  • 🔖 Save To Your Account


comments powered by Disqus