Database Reference
In-Depth Information
Note
Although every major database vendor supports the type of view I've described in
this section, several vendors are now supporting what is known as an indexed (or
materialized ) view. An indexed view is different from a “regular” view in that it
does store data, and youcan index its fields in order to improve the speed at which
the RDBMS processes the view's data. A full discussion of indexed views is bey-
ond the scope of this topic because it is a vendor-specific implementation issue.
However, you should research this topic further if you are working with RDBMS
software such as Oracle, Microsoft SQL Server, IBM DB2, or Sybase SQL, or if
you are working within a data warehouse scenario.
Keys
Keys are special fields that play very specific roles within a table, and the type of key de-
termines its purpose within the table. There are several types of keys a table may contain,
but the two most significant ones are the primary key and the foreign key.
A primary key is a field or group of fields that uniquely identifies each record within a
table; a primary key composed of two or more fields is known as a composite primary key.
The primary key is absolutely the most important key in the entire table.
• A primary key value identifies a specific record throughout the entire database.
• The primary key field identifies a given table throughout the entire database.
• The primary key enforces table-level integrity and helps establish relationships
with other tables in the database. (You'll learn more about relationships in the next
section.)
Every table in your database should have a primary key!
TheA GENT IDfieldin Figure3.11 isagoodexampleofaprimarykey.Ituniquelyidentifies
each agent within the AGENTS table and helps to guarantee table-level integrity by ensur-
ing nonduplicate records. It also establishes relationships between the AGENTS table and
other tables in the database, as in the case with the ENTERTAINERS table shown in the
example.
Search WWH ::




Custom Search