DELETE CASCADE

DELETE CASCADE

am 05.04.2010 11:18:20 von Aveek Misra

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=3DInnoDB DEFAULT CHARSET=3Dlatin1=20


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=3DInnoDB DEFAULT CHARSET=3Dlatin1


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 i=
s not what I intended. I want that the delete cascade should take effect wh=
en "all" the rows in cfg_tags with 'mycluster' are deleted. Should I then r=
emove the "delete cascade" condition and take care of this myself?


Thanks
Aveek




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql-2@m.gmane.o rg

Re: DELETE CASCADE

am 06.04.2010 09:04:31 von muhammad subair

--000e0cd4d334adc75204838c0e1d
Content-Type: text/plain; charset=ISO-8859-1

On Mon, Apr 5, 2010 at 4:18 PM, Aveek Misra wrote:

> 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
>

how data 'mycluster' can duplicate, while he is the primary key in cfg_tags?

--
Muhammad Subair

--000e0cd4d334adc75204838c0e1d--