MySQL Forums
Forum List  »  InnoDB

foreign key data corruption?
Posted by: Borre Mosch
Date: February 13, 2009 09:17AM

Hi,

I have a database in which 2 tables (using the innoDB storage engine) exist:

CREATE TABLE IF NOT EXISTS `table1` (
`table2_id` int(11) NOT NULL,
PRIMARY KEY (`table2_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `table2` (
`id` int(11) NOT NULL,
`name` varchar(64) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

There is also a foreign key constraint between the 2 tables:

ALTER TABLE `table1`
ADD CONSTRAINT `table1_ibfk_1` FOREIGN KEY (`table2_id`) REFERENCES `table2` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

Now there is a row in table1 with table2_id '15'. This id, however, does not exist in table2. When I delete the row and try to re-insert it, this obviously fails as it should. My question is: is this, under certain circumstances, expected behaviour, or is some serious data corruption involved?

Thanks in advance,

Borre

Options: ReplyQuote


Subject
Views
Written By
Posted
foreign key data corruption?
2424
February 13, 2009 09:17AM


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.