1CREATE TABLE child_table
2(
3 column1 datatype [ NULL | NOT NULL ],
4 column2 datatype [ NULL | NOT NULL ],
5 ...
6
7 CONSTRAINT fk_name
8 FOREIGN KEY (child_col1, child_col2, ... child_col_n)
9 REFERENCES parent_table (parent_col1, parent_col2, ... parent_col_n)
10 ON DELETE CASCADE
11 [ ON UPDATE { NO ACTION | CASCADE | SET NULL | SET DEFAULT } ]
12);
1CREATE TABLE child (
2 id INT,
3 parent_id INT,
4 INDEX par_ind (parent_id),
5 FOREIGN KEY (parent_id)
6 REFERENCES parent(id)
7 ON DELETE CASCADE
8) ENGINE=INNODB;