List:General Discussion« Previous MessageNext Message »
From:Aveek Misra Date:April 5 2010 9:18am
Subject:DELETE CASCADE
View as plain text  
I have the following two tables

 CREATE TABLE `cfg_tags` (
  `cluster` varbinary(128) NOT NULL,
  `tag` varbinary(128) NOT NULL,
  `user` varchar(40) NOT NULL,
  PRIMARY KEY (`cluster`,`tag`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 


CREATE TABLE `cfg_cluster_info` (
  `cluster` varbinary(128) NOT NULL,
  `admin` varbinary(128) NOT NULL,
  PRIMARY KEY (`cluster`),
  CONSTRAINT `cfg_cluster_info_ibfk_1` FOREIGN KEY (`cluster`) REFERENCES `cfg_tags`
(`cluster`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1


mysql> select * from cfg_tags;
+-----------+------+--------+
| cluster   | tag  | user   |
+-----------+------+--------+
| mycluster | tag1 | aveekm |
| mycluster | tag2 | aveekm |
+-----------+------+--------+

Now when I delete one row from this table for the cluster 'mycluster', all the matching
rows in the table cfg_cluster_info are deleted. However this is not what I intended. I
want that the delete cascade should take effect when "all" the rows in cfg_tags with
'mycluster' are deleted. Should I then remove the "delete cascade" condition and take
care of this myself?


Thanks
Aveek



Thread
DELETE CASCADEAveek Misra5 Apr
  • Re: DELETE CASCADEmuhammad subair6 Apr