|
| 1 | +drop table if exists t0,t1,t2,t3,t4; |
| 2 | +drop table if exists t0,t5,t6,t7,t8,t9,t1_1,t1_2,t9_1,t9_2; |
| 3 | +drop table if exists _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl, _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410, child_table, child_table_old, child_table_new; |
| 4 | +drop table if exists parent_table, parent_table_old, parent_table_new; |
| 5 | +SET FOREIGN_KEY_CHECKS=1; |
| 6 | +CREATE TABLE parent_table ( |
| 7 | +id INT NOT NULL, |
| 8 | +PRIMARY KEY (id) |
| 9 | +); |
| 10 | +CREATE TABLE child_table ( |
| 11 | +id INT NOT NULL, |
| 12 | +parent_id INT, |
| 13 | +PRIMARY KEY (id), |
| 14 | +KEY parent_id_idx (parent_id), |
| 15 | +CONSTRAINT `child_parent_fk` FOREIGN KEY (parent_id) REFERENCES parent_table(id) ON DELETE NO ACTION |
| 16 | +); |
| 17 | +insert into parent_table values (1), (2); |
| 18 | +insert into child_table values (10, 1); |
| 19 | +insert into child_table values (11, 1); |
| 20 | +insert into child_table values (12, 2); |
| 21 | +insert into child_table values (13, 2); |
| 22 | +CREATE TABLE _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl ( |
| 23 | +id INT NOT NULL, |
| 24 | +parent_id INT, |
| 25 | +PRIMARY KEY (id), |
| 26 | +KEY parent_id_idx (parent_id), |
| 27 | +CONSTRAINT `vrepl_child_parent_fk` FOREIGN KEY (parent_id) REFERENCES parent_table(id) ON DELETE NO ACTION |
| 28 | +); |
| 29 | +insert into _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl select * from child_table; |
| 30 | +CREATE TABLE _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410 ( |
| 31 | +id INT NOT NULL, |
| 32 | +parent_id INT, |
| 33 | +PRIMARY KEY (id), |
| 34 | +KEY parent_id_idx (parent_id), |
| 35 | +CONSTRAINT `hold_child_parent_fk` FOREIGN KEY (parent_id) REFERENCES parent_table(id) ON DELETE NO ACTION |
| 36 | +); |
| 37 | +insert into _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410 select * from child_table; |
| 38 | +insert into child_table values (100, 100); |
| 39 | +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child_table`, CONSTRAINT `child_parent_fk` FOREIGN KEY (`parent_id`) REFERENCES `parent_table` (`id`)) |
| 40 | +insert into _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl values (101, 101); |
| 41 | +insert into _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410 values (102, 102); |
| 42 | +delete from parent_table where id=1; |
| 43 | +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child_table`, CONSTRAINT `child_parent_fk` FOREIGN KEY (`parent_id`) REFERENCES `parent_table` (`id`)) |
| 44 | +delete from child_table; |
| 45 | +delete from parent_table where id=1; |
| 46 | +drop table parent_table; |
| 47 | +ERROR HY000: Cannot drop table 'parent_table' referenced by a foreign key constraint 'child_parent_fk' on table 'child_table'. |
| 48 | +drop table child_table; |
| 49 | +drop table parent_table; |
| 50 | +drop table _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl; |
| 51 | +drop table _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410; |
| 52 | +CREATE TABLE parent_table ( |
| 53 | +id INT NOT NULL, |
| 54 | +PRIMARY KEY (id) |
| 55 | +); |
| 56 | +CREATE TABLE child_table ( |
| 57 | +id INT NOT NULL, |
| 58 | +parent_id INT, |
| 59 | +PRIMARY KEY (id), |
| 60 | +KEY parent_id_idx (parent_id), |
| 61 | +CONSTRAINT `child_parent_fk` FOREIGN KEY (parent_id) REFERENCES parent_table(id) ON DELETE CASCADE |
| 62 | +); |
| 63 | +insert into parent_table values (1), (2); |
| 64 | +insert into child_table values (10, 1); |
| 65 | +insert into child_table values (11, 1); |
| 66 | +insert into child_table values (12, 2); |
| 67 | +insert into child_table values (13, 2); |
| 68 | +CREATE TABLE _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl ( |
| 69 | +id INT NOT NULL, |
| 70 | +parent_id INT, |
| 71 | +PRIMARY KEY (id), |
| 72 | +KEY parent_id_idx (parent_id), |
| 73 | +CONSTRAINT `vrepl_child_parent_fk` FOREIGN KEY (parent_id) REFERENCES parent_table(id) ON DELETE CASCADE |
| 74 | +); |
| 75 | +insert into _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl select * from child_table; |
| 76 | +CREATE TABLE _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410 ( |
| 77 | +id INT NOT NULL, |
| 78 | +parent_id INT, |
| 79 | +PRIMARY KEY (id), |
| 80 | +KEY parent_id_idx (parent_id), |
| 81 | +CONSTRAINT `hold_child_parent_fk` FOREIGN KEY (parent_id) REFERENCES parent_table(id) ON DELETE CASCADE |
| 82 | +); |
| 83 | +insert into _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410 select * from child_table; |
| 84 | +insert into child_table values (200, 200); |
| 85 | +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child_table`, CONSTRAINT `child_parent_fk` FOREIGN KEY (`parent_id`) REFERENCES `parent_table` (`id`) ON DELETE CASCADE) |
| 86 | +insert into _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl values (201, 201); |
| 87 | +insert into _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410 values (202, 202); |
| 88 | +delete from parent_table where id=1; |
| 89 | +select * from child_table; |
| 90 | +id parent_id |
| 91 | +12 2 |
| 92 | +13 2 |
| 93 | +select * from _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl; |
| 94 | +id parent_id |
| 95 | +10 1 |
| 96 | +11 1 |
| 97 | +12 2 |
| 98 | +13 2 |
| 99 | +201 201 |
| 100 | +select * from _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410; |
| 101 | +id parent_id |
| 102 | +10 1 |
| 103 | +11 1 |
| 104 | +12 2 |
| 105 | +13 2 |
| 106 | +202 202 |
| 107 | +drop table parent_table; |
| 108 | +ERROR HY000: Cannot drop table 'parent_table' referenced by a foreign key constraint 'child_parent_fk' on table 'child_table'. |
| 109 | +drop table child_table; |
| 110 | +drop table parent_table; |
| 111 | +drop table _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl; |
| 112 | +drop table _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410; |
| 113 | +CREATE TABLE parent_table ( |
| 114 | +id INT NOT NULL, |
| 115 | +PRIMARY KEY (id) |
| 116 | +); |
| 117 | +CREATE TABLE child_table ( |
| 118 | +id INT NOT NULL, |
| 119 | +parent_id INT, |
| 120 | +PRIMARY KEY (id), |
| 121 | +KEY parent_id_idx (parent_id), |
| 122 | +CONSTRAINT `child_parent_fk` FOREIGN KEY (parent_id) REFERENCES parent_table(id) ON DELETE SET NULL |
| 123 | +); |
| 124 | +insert into parent_table values (1), (2); |
| 125 | +insert into child_table values (10, 1); |
| 126 | +insert into child_table values (11, 1); |
| 127 | +insert into child_table values (12, 2); |
| 128 | +insert into child_table values (13, 2); |
| 129 | +CREATE TABLE _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl ( |
| 130 | +id INT NOT NULL, |
| 131 | +parent_id INT, |
| 132 | +PRIMARY KEY (id), |
| 133 | +KEY parent_id_idx (parent_id), |
| 134 | +CONSTRAINT `vrepl_child_parent_fk` FOREIGN KEY (parent_id) REFERENCES parent_table(id) ON DELETE SET NULL |
| 135 | +); |
| 136 | +insert into _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl select * from child_table; |
| 137 | +CREATE TABLE _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410 ( |
| 138 | +id INT NOT NULL, |
| 139 | +parent_id INT, |
| 140 | +PRIMARY KEY (id), |
| 141 | +KEY parent_id_idx (parent_id), |
| 142 | +CONSTRAINT `hold_child_parent_fk` FOREIGN KEY (parent_id) REFERENCES parent_table(id) ON DELETE SET NULL |
| 143 | +); |
| 144 | +insert into _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410 select * from child_table; |
| 145 | +insert into child_table values (300, 300); |
| 146 | +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child_table`, CONSTRAINT `child_parent_fk` FOREIGN KEY (`parent_id`) REFERENCES `parent_table` (`id`) ON DELETE SET NULL) |
| 147 | +insert into _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl values (301, 301); |
| 148 | +insert into _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410 values (302, 302); |
| 149 | +delete from parent_table where id=1; |
| 150 | +select * from child_table; |
| 151 | +id parent_id |
| 152 | +10 NULL |
| 153 | +11 NULL |
| 154 | +12 2 |
| 155 | +13 2 |
| 156 | +select * from _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl; |
| 157 | +id parent_id |
| 158 | +10 1 |
| 159 | +11 1 |
| 160 | +12 2 |
| 161 | +13 2 |
| 162 | +301 301 |
| 163 | +select * from _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410; |
| 164 | +id parent_id |
| 165 | +10 1 |
| 166 | +11 1 |
| 167 | +12 2 |
| 168 | +13 2 |
| 169 | +302 302 |
| 170 | +drop table parent_table; |
| 171 | +ERROR HY000: Cannot drop table 'parent_table' referenced by a foreign key constraint 'child_parent_fk' on table 'child_table'. |
| 172 | +drop table child_table; |
| 173 | +drop table parent_table; |
| 174 | +drop table _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl; |
| 175 | +drop table _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410; |
| 176 | +CREATE TABLE _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl ( |
| 177 | +id INT NOT NULL, |
| 178 | +PRIMARY KEY (id) |
| 179 | +); |
| 180 | +CREATE TABLE child_table ( |
| 181 | +id INT NOT NULL, |
| 182 | +parent_id INT, |
| 183 | +PRIMARY KEY (id), |
| 184 | +KEY parent_id_idx (parent_id), |
| 185 | +CONSTRAINT `child_parent_fk` FOREIGN KEY (parent_id) REFERENCES _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl(id) ON DELETE RESTRICT |
| 186 | +); |
| 187 | +insert into _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl values (1), (2); |
| 188 | +insert into child_table values (10, 1); |
| 189 | +insert into child_table values (11, 1); |
| 190 | +insert into child_table values (12, 2); |
| 191 | +insert into child_table values (13, 2); |
| 192 | +insert into child_table values (400, 400); |
| 193 | +delete from _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl where id=1; |
| 194 | +select * from child_table; |
| 195 | +id parent_id |
| 196 | +10 1 |
| 197 | +11 1 |
| 198 | +12 2 |
| 199 | +13 2 |
| 200 | +400 400 |
| 201 | +drop table _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl; |
| 202 | +drop table if exists _84371a37_6153_11eb_9917_f875a4d24e90_20210128122816_vrepl, _vt_HOLD_6ace8bcef73211ea87e9f875a4d24e90_20200915120410, child_table, child_table_old, child_table_new; |
| 203 | +drop table if exists parent_table, parent_table_old, parent_table_new; |
0 commit comments