MySQL Forums
Forum List  »  InnoDB

How can I delete 2 tables with foreign keys.
Posted by: Alexander Banin
Date: August 23, 2006 08:03PM

Hello!

The problem is to delete 2 tables like this:


CREATE TABLE `t1` (
`s4` int(11) default NULL,
`s5` int(11) default NULL,
PRIMARY KEY (`s4`),
KEY `s5_ind` (`s5`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

CREATE TABLE `t2` (
`s2` int(11) NOT NULL default '0',
`s3` int(11) default NULL,
PRIMARY KEY (`s2`),
KEY `s3_ind` (`s3`)
) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

ALTER TABLE `t1`
ADD CONSTRAINT `t1_ibfk_2` FOREIGN KEY (`s5`) REFERENCES `t2` (`s2`) ON DELETE CASCADE;

ALTER TABLE `t2`
ADD CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`s3`) REFERENCES `t1` (`s4`) ON DELETE CASCADE;


If i try to delete one of tables the error is a foreign key constraint fails.
If i try to drop one of rows with link (s5 from t1 for example) a get the error (errno: 150) as well.

Is there any way to delete this tables without drop all database?

p.s. Sorry for my English :))

Options: ReplyQuote


Subject
Views
Written By
Posted
How can I delete 2 tables with foreign keys.
2283
August 23, 2006 08:03PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.