| 1 |
create table t1 (f1 int primary key) engine=innodb; |
| 2 |
create table t2 (f1 int primary key, |
| 3 |
constraint c1 foreign key (f1) references t1(f1) |
| 4 |
on update cascade |
| 5 |
on delete cascade) engine=innodb; |
| 6 |
create table t3 (f1 int primary key, |
| 7 |
constraint c2 foreign key (f1) references t1(f1) |
| 8 |
on update cascade |
| 9 |
on delete cascade) engine=innodb; |
| 10 |
show create table t1; |
| 11 |
Table Create Table |
| 12 |
t1 CREATE TABLE `t1` ( |
| 13 |
`f1` int NOT NULL, |
| 14 |
PRIMARY KEY (`f1`) |
| 15 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
| 16 |
show create table t2; |
| 17 |
Table Create Table |
| 18 |
t2 CREATE TABLE `t2` ( |
| 19 |
`f1` int NOT NULL, |
| 20 |
PRIMARY KEY (`f1`), |
| 21 |
CONSTRAINT `c1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON DELETE CASCADE ON UPDATE CASCADE |
| 22 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
| 23 |
show create table t3; |
| 24 |
Table Create Table |
| 25 |
t3 CREATE TABLE `t3` ( |
| 26 |
`f1` int NOT NULL, |
| 27 |
PRIMARY KEY (`f1`), |
| 28 |
CONSTRAINT `c2` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON DELETE CASCADE ON UPDATE CASCADE |
| 29 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
| 30 |
insert into t1 values (1); |
| 31 |
insert into t1 values (2); |
| 32 |
insert into t1 values (3); |
| 33 |
insert into t2 values (1); |
| 34 |
insert into t2 values (2); |
| 35 |
insert into t2 values (3); |
| 36 |
insert into t3 values (1); |
| 37 |
insert into t3 values (2); |
| 38 |
insert into t3 values (3); |
| 39 |
select f1 from t1; |
| 40 |
f1 |
| 41 |
1 |
| 42 |
2 |
| 43 |
3 |
| 44 |
select f1 from t2; |
| 45 |
f1 |
| 46 |
1 |
| 47 |
2 |
| 48 |
3 |
| 49 |
select f1 from t3; |
| 50 |
f1 |
| 51 |
1 |
| 52 |
2 |
| 53 |
3 |
| 54 |
SET DEBUG='+d,dml_cascade_only_once'; |
| 55 |
SET DEBUG='+d,row_upd_cascade_lock_wait_err'; |
| 56 |
update t1 set f1 = 100 where f1 = 2; |
| 57 |
select f1 from t1; |
| 58 |
f1 |
| 59 |
1 |
| 60 |
3 |
| 61 |
100 |
| 62 |
select f1 from t2; |
| 63 |
f1 |
| 64 |
1 |
| 65 |
3 |
| 66 |
100 |
| 67 |
select f1 from t3; |
| 68 |
f1 |
| 69 |
1 |
| 70 |
3 |
| 71 |
100 |
| 72 |
drop table t2; |
| 73 |
drop table t3; |
| 74 |
drop table t1; |