CompTIA DataSys+ (DS0-001)Database FundamentalsMedium
A database developer wants to ensure that a `ProductID` column in an `Orders` table always refers to an existing `ProductID` in the `Products` table. If an attempt is made to insert an order with a `ProductID` that does not exist in the `Products` table, the operation should fail. Which type of key should be used in the `Orders` table to enforce this referential integrity?
- AForeign key
- BSuper key
- CPrimary key
- DCandidate key
Show answer & explanationAnswer & explanation
Correct answer: A. Foreign key
A foreign key is used to link two tables together. It references the primary key of another table, ensuring that values in the foreign key column exist in the referenced primary key column, thus enforcing referential integrity.
Why the other options are wrong
- B. A super key is any set of attributes that uniquely identifies a row, which may include redundant attributes.
- C. A primary key uniquely identifies a row within its own table.
- D. A candidate key is a minimal super key; it can uniquely identify a row but isn't necessarily the chosen primary key.
Foreign Key
A column or set of columns in a relational database table that provides a link between data in two tables. It refers to the primary key in another table.
- Establishes and enforces a link between two tables.
- Ensures referential integrity.
- Can contain NULL values if not also specified as NOT NULL.
Memory trick: Keys unlock and link your data.