Hi ! :D
I would like you help me to solve the following problem:
Suppose the tables below:
create table book
(
Bk_Id integer(4) unsigned not null auto_increment primary key,
Bk_Name varchar(20)
) type = innoDb;
create table page
(
Pg_Id integer(4) unsigned not null auto_increment primary key,
Pg_Notes varchar(20),
Pg_Book integer(4) unsigned not null
) type = innoDb;
Create index IPg_Book on page (Pg_Book);
One book must have one or more pages and one page must be a part of
one book. It must be impossible to have one book with no pages or
one page not associated to one book. Because this, the following
constraint were created:
alter table book Add Constraint Foreign Key (Bk_Id)
References page(Pg_Book);
alter table page Add Constraint Foreign Key (Pg_Book)
References book(Bk_Id);
The problem is that creating this two constraints, I can't insert
records in these tables. See the example:
begin;
insert into book (Bk_Id, Bk_Name) VALUES (1, 'Test');
insert into page (Pg_Book, Pg_Notes) VALUES (1, 'Test');
commit;
Both insert commands returns:
Cannot add a child row: a foreign key constraint fails
Is there a way to create constraints that implements the rules I
need?
Bye,
sql,query
-------------------------------------------------------------------------
++ Dyego Souza do Carmo ++ Dep. Desenvolvimento
-------------------------------------------------------------------------
E S C R I B A I N F O R M A T I C A
-------------------------------------------------------------------------
The only stupid question is the unasked one (somewhere in Linux's HowTo)
Linux registred user : #230601
--
$ look into "my eyes" Phone : +55 041 296-2311 r.112
look: cannot open my eyes Fax : +55 041 296-6640
-------------------------------------------------------------------------
Reply: [EMAIL PROTECTED]
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php