Re: Beginner help needed
Posted in 1995
Topics: Triggers, Constraints & Referential Integrity
> > In relations - I am having a hard time understanding the difference in >foriegn key and primary key, if both have or are the same attribute. In >the example given, what they call the foreign key acts like what I would >consider the primary key and vice versa.... > consider 2 tables: Employee and Colleges Employee --------- Employee_id (primary key for Employee) . . Colleges . -------- College_attended --------------->College_code (primary key for Colleges) College_attended is a foreign key because it is the primary key of another table. It is considered to be data about an employee. In this example, (used in excruciating detail in many texts and sample dbs) Colleges is a "lookup" table to validate College_code. ...snip... > Book says Primary key must be unique, or have the property of being >unique - > > then goes on to say that data in the foreign key must match the data >in the primary key. okay, if that is the case, how can the primary key >be unique? > > Please answer in public or in Email to: > > mark.robbins@ssanctum.com A primary key must be unique because the postulators of the relational calculus and algebra said so... It is a fundamental concept to relational "technology". Many products will build this into their syntax and code. Sometimes, identifying the primary key can be a challenge. Anyway, the definition (in "everyday" language) of a foreign key is a column in a table that is a primary key in another. Disclaimer... This is NOT a rigorous definition; it's simply one that's easily understandable.