orders.customer_id references customers.id. What is customer_id?
Options
- A primary key of the orders table that identifies each order
- A foreign key that links each order to a customer row (Correct option)
- The name of an index that was created on the orders table
- A duplicate column that should be deleted from the table
Answer
A foreign key: it links each order to a row in another table
Why
A foreign key is a column that stores the primary key of a row in another table, creating a relationship: each order belongs to one customer.
The database can enforce it: you cannot create an order for a customer that does not exist, or delete a customer who still has orders (unless you configure cascade).
Remember
Foreign key = link to a row in another table.