Table Relationships

Understanding how one table is related to another lets you construct different types of joins.

Primary Key Identifiers Key

Every table in the iqdemo database has a primary key. A primary key is one or more columns that uniquely identify a row in the table. For example, an employee number uniquely identifies an employee - EmployeeID is the primary key of the Employees table.

The SalesOrderItems table is an example of a table with two columns that make up the primary key. The order ID by itself does not uniquely identify a row in the SalesOrderItems table because there can be several items in an order. Also, the LineID number does not uniquely identify a row in the SalesOrderItems table. Both the order ID name and LineID are required to uniquely identify a row in the SalesOrderItems table. Therefore, the primary key of the table is both columns taken together.

Foreign Keys for Table Relationships

Several tables in the iqdemo database refer to other tables in the database. For example, in the SalesOrders table, the SalesRepresentative column indicates which employee is responsible for an order. Only enough information to uniquely identify an employee is kept in the SalesOrders table. The SalesRepresentative column in the SalesOrders table is a foreign key to the Employees table.

A foreign key is one or more columns that contain candidate key values from another table. (For more about candidate keys, see System Administration Guide: Volume 1 > Data Integrity > Data Integrity Overview > Data Integrity Tools.)