mysql - Cascade Not Working -
i have couple tables weakly connected , delete work across both of them when delete main table.
table 1:
create table car( cid integer, color varchar(10), primary key (cid) ); create table tags( tid integer, expdate varchar(10), cid integer, primary key (tid, cid), foreign key (cid) references car(cid) on delete cascade );
but when delete car car table, not deleted tags table. i've tried adding constraint after table creation same result.
set sql_mode="no_auto_value_on_zero"; set time_zone = "+00:00"; -- -------------------------------------------------------- -- -- table structure table `car` -- create table if not exists `car` ( `cid` int(11) not null auto_increment, `color` varchar(10) default null, primary key (`cid`) ) engine=innodb default charset=latin1 auto_increment=5 ; -- -- dumping data table `car` -- insert `car` (`cid`, `color`) values (2, 'b'), (4, 'a'); -- -------------------------------------------------------- -- -- table structure table `tags` -- create table if not exists `tags` ( `tid` int(11) not null auto_increment, `expdate` varchar(10) default null, `cid` int(11) not null default '0', primary key (`tid`,`cid`), key `cid` (`cid`) ) engine=innodb default charset=latin1 auto_increment=7 ; -- -- dumping data table `tags` -- insert `tags` (`tid`, `expdate`, `cid`) values (3, 'aa', 2), (4, 'bb', 2), (5, '11', 4), (6, '22', 4); -- -- constraints dumped tables -- -- -- constraints table `tags` -- alter table `tags` add constraint `tags_ibfk_1` foreign key (`cid`) references `car` (`cid`) on delete cascade;
--now delete record ;
--delete car cid=4;
Comments
Post a Comment