View Single Post

  #2 (permalink)  
Old 10-21-2005
Bill Karwin
 
Posts: n/a
Default Re: Compound and foreign keys

Jimi Hullegård wrote:
> [OK, first of all, I know this is not a MySQL specific question, but I
> couldn't find any newsgroup about SQL in general.]


comp.databases is probably the closest thing to a general SQL newsgroup.

> One of the statements was (translated from swedish):
> "A compound key is a primary key based on at least two foreign keys."


Consider this example of a many-to-many table:

create table employeeProjectMapping (
employee_id integer not null references employee(employee_id),
project_id integer not null references project(project_id),
primary key(employee_id, project_id)
);

This fits the statement given in your exam. However, though the
statement is true, it is not a complete definition of a compound key.
It would have been more clear if the statement were, "One example of a
compound key is a primary key based on at least two foreign keys."

This is not the only use of compound keys. It is not unusual to define
a primary key over multiple columns, which are _not_ themselves foreign
keys.

Besides, the statement only mentioned "key" (unless there's an issue
with the translation from Swedish). I'm pretty sure "key" can refer to
a primary key, a foreign key, or even another set of columns that can be
used to identify records in the table.

In my opinion, you are correct in disputing this item on the exam. Good
luck!

Regards,
Bill K.
Reply With Quote