MySQL Forums
Forum List  »  General

implement tree as adjacency list
Posted by: Yuwei Zhao
Date: November 16, 2004 10:31AM

Hi!

I tried to create a table to model a tree structure:

create table personnel
(emp varchar(20) primary key,
boss varchar(20),
index(boss, emp),
foreign key (boss) references personnel(emp) on update cascade on delete cascade) type = innodb;

insert into personnel values('Albert', null);
insert into personnel values('Bert', 'Albert');
insert into personnel values('Chuck', 'Albert');
insert into personnel values('Donna', 'Chuck');
insert into personnel values('Eddie', 'Chuck');
insert into personnel values('Fred', 'Chuck');

If I try to remove emp 'Albert'

delete from personnel where emp = 'Albert'

it works fine and all records are removed.

But if I try to update a record

update personnel set emp = 'david' where emp = 'Albert';

it fails: ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails

Does anyone have a fix to this problem?

/Wei

Options: ReplyQuote


Subject
Written By
Posted
implement tree as adjacency list
November 16, 2004 10:31AM


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.