All quizzesEasy
Keys, Types & Constraints
Preview — 3 of 10 questions
What is a surrogate key in a relational database?
AA natural key derived from the business domain
BA system-generated key with no business meaning (e.g., auto-increment integer or UUID)
CA composite key made up of multiple columns
DA key shared between two related tables
What does a FOREIGN KEY constraint enforce in a relational database?
javascript
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
customer_id INT NOT NULL REFERENCES customers(id)
);AIt ensures the column values are unique across the table
BIt ensures that a value in one table corresponds to an existing value in another table (referential integrity)
CIt prevents NULL values in the referenced column
DIt automatically creates an index on the referenced column
How is a one-to-many relationship typically implemented in a relational database?
javascript
CREATE TABLE customers (id SERIAL PRIMARY KEY, name TEXT NOT NULL);
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
customer_id INT NOT NULL REFERENCES customers(id),
total NUMERIC(10,2)
);ABy adding a foreign key column in the child table referencing the parent table's primary key
BBy creating a junction table between the two entities
CBy adding a column in the parent table referencing the child table's primary key
DBy duplicating rows in both tables
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.