Complete the code to specify that deleting a parent row will delete matching child rows.
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id) ON DELETE [1]
);The CASCADE option deletes child rows when the parent row is deleted.
Complete the code to prevent deletion of a parent row if child rows exist.
ALTER TABLE orders
ADD CONSTRAINT fk_customer FOREIGN KEY (customer_id) REFERENCES customers(customer_id) ON DELETE [1];The RESTRICT option prevents deleting a parent row if child rows exist.
Fix the error in the foreign key definition to set the child foreign key to NULL when the parent is deleted.
CREATE TABLE orders (
order_id INT PRIMARY KEY,
customer_id INT,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id) ON DELETE [1]
);The SET NULL option sets the foreign key column to NULL when the parent row is deleted.
Fill both blanks to create a foreign key that prevents deletion and updates child keys on parent update.
CREATE TABLE orders ( order_id INT PRIMARY KEY, customer_id INT, FOREIGN KEY (customer_id) REFERENCES customers(customer_id) ON DELETE [1] ON UPDATE [2] );
RESTRICT prevents deleting a parent row if child rows exist, and CASCADE updates child foreign keys when the parent key changes.
Fill all three blanks to create a foreign key that sets child keys to NULL on delete, cascades updates, and restricts deletes on another key.
CREATE TABLE orders ( order_id INT PRIMARY KEY, customer_id INT, product_id INT, FOREIGN KEY (customer_id) REFERENCES customers(customer_id) ON DELETE [1] ON UPDATE [2], FOREIGN KEY (product_id) REFERENCES products(product_id) ON DELETE [3] );
The first foreign key sets child keys to NULL on delete (SET NULL) and cascades updates (CASCADE). The second foreign key restricts deletion (RESTRICT).