Q:

What Is the difference between a primary key and a secondary key?

A:

Quick Answer

A primary key is a unique identifier for a discrete object on a table, and a secondary key provides a second reference point for objects whose primary keys do not adequately distinguish them for reference purposes. The two are vital to the functions of databases, list tables and other archival tools.

Continue Reading

Full Answer

There are several examples of primary keys, including:

  • Unique last name
  • Social Security number
  • Online username

These keys allow for the unique treatment of objects on a table by search algorithms and other programs as well as by human reference searches. Without strong primary keys, objects could be mislabeled as identical or databases rendered impossible to search effectively. Strings of unique numbers generated inside a predetermined numerical set are the most common primary keys, and they are used by everyone from insurance providers to reference librarians.

Examples of secondary keys include:

  • Street address number
  • Phone number
  • Middle name

In the event that a primary key is not enough to distinguish an object, a secondary key can be used to render that object unique. It is processed and sorted in relation to a primary key, clarifying search terms so that only desired results appear when a table is consulted. This creates clearer, cleaner databases.

Some keys, called foreign keys, are objects on a given table that function as keys to entire additional tables. These keys are used in concert with primary keys to streamline database size and store relevant information without redundancy. A strong understanding of keys is the first step to creating a usable table.

Learn more about Computer Programming

Related Questions

Explore