create database mydb0; use mydb0; create table parent ( a int primary key, b int not null, c int not null, unique(b) using hash, index(c)) engine = ndb; create database mydb1; use mydb1; create table child ( a int primary key, b int not null, c int not null, constraint fk1 foreign key(a) references mydb0.parent (a), unique(b) using hash, index(c)) engine = ndb; show create table child; Table Create Table child CREATE TABLE `child` ( `a` int(11) NOT NULL, `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`a`), UNIQUE KEY `b` (`b`) USING HASH, KEY `c` (`c`), CONSTRAINT `fk1` FOREIGN KEY (`a`) REFERENCES `mydb0`.`parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci alter table child algorithm=copy, add constraint fk2 foreign key (b) references mydb0.parent(a); show create table child; Table Create Table child CREATE TABLE `child` ( `a` int(11) NOT NULL, `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`a`), UNIQUE KEY `b` (`b`) USING HASH, KEY `c` (`c`), CONSTRAINT `fk1` FOREIGN KEY (`a`) REFERENCES `mydb0`.`parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk2` FOREIGN KEY (`b`) REFERENCES `mydb0`.`parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci alter table child algorithm=inplace, add constraint fk3 foreign key (c) references mydb0.parent(a); show create table child; Table Create Table child CREATE TABLE `child` ( `a` int(11) NOT NULL, `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`a`), UNIQUE KEY `b` (`b`) USING HASH, KEY `c` (`c`), CONSTRAINT `fk1` FOREIGN KEY (`a`) REFERENCES `mydb0`.`parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk2` FOREIGN KEY (`b`) REFERENCES `mydb0`.`parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk3` FOREIGN KEY (`c`) REFERENCES `mydb0`.`parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci alter table child algorithm=copy, drop foreign key fk2; show create table child; Table Create Table child CREATE TABLE `child` ( `a` int(11) NOT NULL, `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`a`), UNIQUE KEY `b` (`b`) USING HASH, KEY `c` (`c`), CONSTRAINT `fk1` FOREIGN KEY (`a`) REFERENCES `mydb0`.`parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk3` FOREIGN KEY (`c`) REFERENCES `mydb0`.`parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci alter table child algorithm=inplace, drop foreign key fk3; show create table child; Table Create Table child CREATE TABLE `child` ( `a` int(11) NOT NULL, `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`a`), UNIQUE KEY `b` (`b`) USING HASH, KEY `c` (`c`), CONSTRAINT `fk1` FOREIGN KEY (`a`) REFERENCES `mydb0`.`parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci alter table mydb0.parent algorithm=copy, rename mydb1.parent; show create table child; Table Create Table child CREATE TABLE `child` ( `a` int(11) NOT NULL, `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`a`), UNIQUE KEY `b` (`b`) USING HASH, KEY `c` (`c`), CONSTRAINT `fk1` FOREIGN KEY (`a`) REFERENCES `parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci alter table mydb1.parent algorithm=inplace, rename mydb0.parent; show create table child; Table Create Table child CREATE TABLE `child` ( `a` int(11) NOT NULL, `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`a`), UNIQUE KEY `b` (`b`) USING HASH, KEY `c` (`c`), CONSTRAINT `fk1` FOREIGN KEY (`a`) REFERENCES `mydb0`.`parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci use test; alter table mydb1.child algorithm=copy, add constraint fk2 foreign key (b) references mydb0.parent(a); use mydb1; show create table child; Table Create Table child CREATE TABLE `child` ( `a` int(11) NOT NULL, `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`a`), UNIQUE KEY `b` (`b`) USING HASH, KEY `c` (`c`), CONSTRAINT `fk1` FOREIGN KEY (`a`) REFERENCES `mydb0`.`parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk2` FOREIGN KEY (`b`) REFERENCES `mydb0`.`parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci use test; alter table mydb1.child algorithm=inplace, add constraint fk3 foreign key (c) references mydb0.parent(a); use mydb1; show create table child; Table Create Table child CREATE TABLE `child` ( `a` int(11) NOT NULL, `b` int(11) NOT NULL, `c` int(11) NOT NULL, PRIMARY KEY (`a`), UNIQUE KEY `b` (`b`) USING HASH, KEY `c` (`c`), CONSTRAINT `fk1` FOREIGN KEY (`a`) REFERENCES `mydb0`.`parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk2` FOREIGN KEY (`b`) REFERENCES `mydb0`.`parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk3` FOREIGN KEY (`c`) REFERENCES `mydb0`.`parent` (`a`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci use test; drop database mydb1; drop database mydb0; set @i=2; create database mydb0; use mydb0; create table t0 (a int primary key) engine = innodb; create table t1 (a int primary key) engine = innodb; alter table mydb0.t0 add constraint fk0 foreign key (a) references mydb0.t1(a); alter table mydb0.t1 add constraint fk1 foreign key (a) references mydb0.t0(a); drop database mydb0; set @i=1; create database mydb0; use mydb0; create table t0 (a int primary key) engine = ndb; create table t1 (a int primary key) engine = ndb; alter table mydb0.t0 add constraint fk0 foreign key (a) references mydb0.t1(a); alter table mydb0.t1 add constraint fk1 foreign key (a) references mydb0.t0(a); drop database mydb0; set @i=2; create database mydb0; use mydb0; create table t0 (a int primary key) engine = innodb; create database mydb1; use mydb1; create table t1 (a int primary key) engine = innodb; alter table mydb0.t0 add constraint fk0 foreign key (a) references mydb1.t1(a); alter table mydb1.t1 add constraint fk1 foreign key (a) references mydb0.t0(a); drop database mydb0; ERROR HY000: Cannot drop table 't0' referenced by a foreign key constraint 'fk1' on table 't1'. drop database mydb1; ERROR HY000: Cannot drop table 't1' referenced by a foreign key constraint 'fk0' on table 't0'. alter table mydb0.t0 drop foreign key fk0; drop database mydb0; ERROR HY000: Cannot drop table 't0' referenced by a foreign key constraint 'fk1' on table 't1'. drop database mydb1; drop database mydb0; set @i=1; create database mydb0; use mydb0; create table t0 (a int primary key) engine = ndb; create database mydb1; use mydb1; create table t1 (a int primary key) engine = ndb; alter table mydb0.t0 add constraint fk0 foreign key (a) references mydb1.t1(a); alter table mydb1.t1 add constraint fk1 foreign key (a) references mydb0.t0(a); drop database mydb0; ERROR HY000: Cannot drop table 't0' referenced by a foreign key constraint 'fk1' on table 't1'. drop database mydb1; ERROR HY000: Cannot drop table 't1' referenced by a foreign key constraint 'fk0' on table 't0'. alter table mydb0.t0 drop foreign key fk0; drop database mydb0; ERROR HY000: Cannot drop table 't0' referenced by a foreign key constraint 'fk1' on table 't1'. drop database mydb1; drop database mydb0;