@ -469,8 +469,9 @@ create table t1(a int not null, b int not null, c int, primary key (a), key (b))
create table t3(a int not null, c int not null, d int, primary key (a), key (c)) engine = innodb;
create table t4(a int not null, d int not null, e int, primary key (a), key (d)) engine = innodb;
create table t2(a int not null, b int not null, c int not null, d int not null, e int,
primary key (a), foreign key (b) references t1(b), foreign key (c) references t3(c),
foreign key (d) references t4(d)) engine = innodb;
foreign key (b) references t1(b) on delete cascade,
foreign key (c) references t3(c), foreign key (d) references t4(d))
engine = innodb;
alter table t1 drop index b;
ERROR HY000: Cannot drop index 'b': needed in a foreign key constraint
alter table t3 drop index c;
@ -481,7 +482,8 @@ alter table t2 drop index b;
ERROR HY000: Cannot drop index 'b': needed in a foreign key constraint
alter table t2 drop index b, drop index c, drop index d;
ERROR HY000: Cannot drop index 'b': needed in a foreign key constraint
set foreign_key_checks=0;
create unique index dc on t2 (d,c);
alter table t2 add primary key (a);
insert into t1 values (1,1,1);
insert into t3 values (1,1,1);
insert into t4 values (1,1,1);
@ -497,17 +499,17 @@ t2 CREATE TABLE `t2` (
`d` int(11) NOT NULL,
`e` int(11) DEFAULT NULL,
PRIMARY KEY (`a`),
UNIQUE KEY `dc` (`d`,`c`),
KEY `c` (`c`),
KEY `d` (`d`),
KEY `b` (`b`),
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`b`),
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`b`) ON DELETE CASCADE ,
CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`c`) REFERENCES `t3` (`c`),
CONSTRAINT `t2_ibfk_3` FOREIGN KEY (`d`) REFERENCES `t4` (`d`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
set foreign_key_checks= 1;
set foreign_key_checks=0 ;
drop table if exists t1,t2,t3,t4;
set foreign_key_checks=1 ;
delete from t 1;
select * from t2 ;
a b c d e
drop table if exists t2,t1,t3,t4 ;
create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a))
engine = innodb default charset=utf8;
insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,2,'ad','ad'),(4,4,'afe','afe');