Ipower web hosting - Primary Keys A primary key is used to
Friday, July 27th, 2007Primary Keys A primary key is used to uniquely identify a record in a table. Unique identification for each record is required because there is no other way to find a record without the possibility of finding more than one record, if the unique identifier is not used. Figure 3-21 shows primary key fields of AUTHOR_ID for the AUTHOR table and PUBLICATION_ID for the PUBLICATION table, each being primary key fields for the two tables. Figure 3-21: A primary key uniquely identifies a record in a table. Unique Keys Like a primary key, a unique key is created on a field containing only unique values throughout an entire table. In Figure 3-21, and throughout the rest of this chapter, you may be wondering why integers are used as primary keys rather than the name of an author or a publication, and otherwise. The reason why will be explained later in this book but in general integer value primary keys are known as surrogate keys because they substitute as primary keys for names. For example, the AUTHOR_ID field in the AUTHOR table is a surrogate primary key as a replacement or surrogate for creating the primary on the AUTHOR table NAME field, the full name of the author. It is very unlikely that there will be two authors with the same name. Surrogate keys are used to improve performance. So, why create unique keys that are not primary keys? If surrogate keys are used and the author name is required to be unique, it is common to see unique keys created on name fields such as the AUTHOR table NAME and the PUBLICATION table TITLE fields. A unique key ensures uniqueness across a table. A primary key is always unique, or at least a unique key; however, a primary key is also used to define relationships between tables. Unique keys are not used to define relationships between tables. 1 2 3 4 5 6 7 8 9 10 11 12 2 2 3 3 3 3 3 4 4 4 6 7 Cities in Flight A Case of Conscience Foundation Second Foundation Foundation and Empire Foundation s Edge Prelude to Foundation The Complete Works of Shakespeare Lucifer s Hammer Footfall Ringworld Hocus Pocus PUBLICATION_ID AUTHOR_ID TITLE 1 5 6 Orson Scott Card James Blish Isaac Azimov Larry Niven Jerry Pournelle William Shakespeare Kurt Vonnegut AUTHOR_ID NAME 2 3 4 7 Publication Author Author author_id name Publication publication_id subject_id (FK) author_id (FK) title PUBLICATION_ID uniquely identifies a publication AUTHOR_ID uniquely identifies an author 59 Database Modeling Building Blocks
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.