1.What is the difference between a primary key and a foreign key?
Show hint
One identifies rows in its own table; the other points to rows in another table.
Show solution
- A primary key uniquely identifies each row in a table. It must be unique and cannot be
NULL. A table has at most one primary key (which may span several columns). - A foreign key is a column whose values must match a primary (or unique) key in another table. It creates the relationship between tables and prevents "orphan" rows, such as an order for a customer that does not exist.