Complete the code to create a table with a primary key.
CREATE TABLE users (id INT [1] PRIMARY KEY, name VARCHAR(100));
The AUTO_INCREMENT keyword automatically generates unique values for the primary key column.
Complete the code to add a foreign key constraint.
ALTER TABLE orders ADD CONSTRAINT fk_user_id FOREIGN KEY (user_id) [1] users(id);The REFERENCES keyword defines the foreign key relationship to another table's column.
Fix the error in the table creation by completing the code.
CREATE TABLE products (product_id INT PRIMARY KEY, price [1] DECIMAL(10, 2));
The NOT NULL constraint ensures the price column cannot be empty.
Fill both blanks to create a normalized table with a unique constraint.
CREATE TABLE employees (emp_id INT PRIMARY KEY, email VARCHAR(255) [1] [2]);
The NOT NULL constraint ensures email is always provided, and UNIQUE prevents duplicate emails.
Fill all three blanks to create a table with a composite primary key and a foreign key.
CREATE TABLE enrollment (student_id INT, course_id INT, semester VARCHAR(10), PRIMARY KEY ([1], [2]), FOREIGN KEY (student_id) [3] students(id));
The composite primary key uses student_id and course_id. The foreign key uses REFERENCES to link to the students table.