Complete the code to define a primary key for the 'users' table.
CREATE TABLE users (id SERIAL [1] PRIMARY KEY, name TEXT);The primary key column must be NOT NULL to ensure uniqueness and identification.
Complete the code to create a foreign key in the 'orders' table referencing 'users'.
CREATE TABLE orders (order_id SERIAL PRIMARY KEY, user_id INTEGER [1] REFERENCES users(id));The foreign key column should be NOT NULL to ensure every order is linked to a user.
Fix the error in the foreign key constraint syntax.
ALTER TABLE orders ADD CONSTRAINT fk_user FOREIGN KEY (user_id) [1] users(id);The correct keyword to link a foreign key is REFERENCES.
Fill both blanks to create a table with a composite primary key.
CREATE TABLE enrollment (student_id INTEGER [1], course_id INTEGER [2], PRIMARY KEY (student_id, course_id));
Both columns in a composite primary key must be NOT NULL to ensure uniqueness.
Fill all three blanks to create a foreign key with ON DELETE CASCADE and ON UPDATE CASCADE.
ALTER TABLE orders ADD CONSTRAINT fk_user FOREIGN KEY (user_id) [1] users(id) ON DELETE [2] ON UPDATE [3];
Use REFERENCES to define the foreign key, and CASCADE to automatically update or delete related rows.