CompTIA DataSys+ (DS0-001)Database FundamentalsEasy
A database developer is creating a new `Orders` table. Each order must be uniquely identified, and the system should automatically generate a sequential number for each new order. Additionally, this unique identifier should be the primary means of looking up individual orders efficiently. Which type of key should be implemented for the `OrderID` column to meet these requirements?
- AForeign Key
- BPrimary Key
- CCandidate Key
- DSuper Key
Show answer & explanationAnswer & explanation
Correct answer: B. Primary Key
A Primary Key uniquely identifies each record in a table and is the chosen candidate key for that purpose. It also implicitly creates an index for efficient lookups, aligning with all requirements.
Why the other options are wrong
- A. A Foreign Key establishes a link between data in two tables, ensuring referential integrity, not unique identification within its own table.
- C. A Candidate Key is any column or set of columns that can uniquely identify a row, but not necessarily the chosen one.
- D. A Super Key is a set of attributes that uniquely identifies a record, which can include redundant attributes not needed for uniqueness.
Primary Key
A column or set of columns in a table that uniquely identifies each row in that table. It enforces entity integrity and is typically indexed for efficient data retrieval.
- Must contain unique values.
- Cannot contain NULL values (NOT NULL constraint).
- There can be only one primary key per table.
- Often used for efficient data retrieval and establishing relationships.
Memory trick: PRIMARY keys are the UNIQUE and essential ID for each record!