MySQL CASCADE Options
MySQL CASCADE Options is a SQL statement in the MySQL Specific category. MySQL supports ON DELETE and ON UPDATE referential actions for InnoDB foreign keys. The syntax is FOREIGN KEY (col) REFERENCES parent(id) ON DELETE CASCADE ON UPDATE CASCADE;. It returns cascade options. A typical example: CREATE TABLE orders ( id INT PRIMARY KEY AUTO_INCREMENT, customer_id INT, total DECIMAL(10,2), FOREIGN KEY (customer_id) REFERENCES customers(id) ON DELETE CASCADE ON UPDATE CASCADE ); -- ON DELETE CASCADE: deleting a customer deletes their orders -- ON UPDATE CASCADE: changing customer.id updates orders.customer_id -- Other options: -- ON DELETE SET NULL: sets FK column to NULL -- ON DELETE RESTRICT: prevents deletion -- ON DELETE NO ACTION: same as RESTRICT… A close relative is AUTO_INCREMENT, which mySQL auto-generates sequential integer values for this column. Commonly used with PRIMARY KEY. A close relative is ENGINE, which specifies the MySQL storage engine. InnoDB (default) supports transactions and foreign keys. MyISAM is faster for read-heavy.