This is my table:
CREATE TABLE `pages` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`parent` int(11) DEFAULT NULL,
`label` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
where id is a unique id (autoincrement) and parent is also an id from the same table. If parent is NULL, the page hasn't got parent.
What I want? If I delete one parent, it should auto delete all his childs in the same table. I believe that this can be done using on DELETE CASCADE, and this is the way that I want to do it :). But I've tried many configurations of code, and none of them work. Either table cannot be created, or insert query is not working, because of an error that looks similar to "key not exist".
What I found?
How to recursively delete items from table? - answer is great, but with none of code. This answer to the same question: https://stackoverflow.com/a/9260373/1125465 doesn't work for me. There are some problems with table creation. I think this answer was made in a hurry, and there is some key word missing?
Recursive MySQL Query with relational innoDB this one is simmilar, but not the same case, there are few tables.
Sql server - recursive delete - Come on, there must be a simpliest answer...
Technical info:
- mysql Ver 14.14 Distrib 5.1.70, for pc-linux-gnu (x86_64) using readline 5.1
- Table engine: InnoDB