[wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't update the child table - HELP

2003-03-19 Thread Paul Larue
Ok people, Thanks for your help. I just upgraded from MySQL 4.0.11 to MySQl
4.0.12 and guess what... IT WORKS!!!

Paul

-Original Message-
From: Furry, Tim [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 19, 2003 6:23 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't
update the child table - HELP


Paul wrote:
I thought about that one but the result will be that if I want to have,
let's say, a list of employees and their associated groups, I would have
to make a UNION select on the 2 tables to get the associated
employee_groups.grp_name since employees.emp_group only contains the ID
of the group name. So only to avoid that, I would prefer to keep the
actual pk/fk mapping. Your solution is somehow interesting since
updating employee_groups.grp_name DOES NOT affect the employees table.

What do you think is better? Keep the existing setup and bang my head
against the wall to find out why it won't work or change to the one you
proposed? Taking into consideration the issue I pointed out above (the
UNION stuff).

Tim sez:
Paul, I don't know anything about MySQL, but some general searching
brought up these interesting things you might want to check.  I agree
with you, updating the child table shouldn't affect the PK/FK mappings
at all unless you're trying to change the child table's FK/PK.  Weird.

These two sites suggest you need to check the version level of your
MySQL (for cascade support):
http://www.geocrawler.com/archives/3/8/2002/5/0/8813034/
http://www.riverside.org/archive/html/mysql/2003-02/msg00392.html

The order in which you declare the ON DELETE/ON UPDATE cascades may be
important:
http://www.faqchest.com/prgm/mysql-l/mysql-03/mysql-0302/mysql-030207/my
sql03020615_23303.html

Probably won't help, but maybe it will.

Tim
___
Tim Furry
Web Developer
Foulston Siefkin LLP




  The WDVL Discussion List from WDVL.COM  
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED]
   Send Your Posts To: [EMAIL PROTECTED]
To change subscription settings to the wdvltalk digest version:
http://wdvl.internet.com/WDVL/Forum/#sub

  http://www.wdvl.com  ___

You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to %%email.unsub%%



 • The WDVL Discussion List from WDVL.COM • 
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] 
   Send Your Posts To: [EMAIL PROTECTED]
To change subscription settings to the wdvltalk digest version:
http://wdvl.internet.com/WDVL/Forum/#sub

  http://www.wdvl.com  ___

You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]


[wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't update the child table - HELP

2003-03-19 Thread Furry, Tim
Paul wrote:
I thought about that one but the result will be that if I want to have,
let's say, a list of employees and their associated groups, I would have
to make a UNION select on the 2 tables to get the associated
employee_groups.grp_name since employees.emp_group only contains the ID
of the group name. So only to avoid that, I would prefer to keep the
actual pk/fk mapping. Your solution is somehow interesting since
updating employee_groups.grp_name DOES NOT affect the employees table.

What do you think is better? Keep the existing setup and bang my head
against the wall to find out why it won't work or change to the one you
proposed? Taking into consideration the issue I pointed out above (the
UNION stuff).

Tim sez:
Paul, I don't know anything about MySQL, but some general searching
brought up these interesting things you might want to check.  I agree
with you, updating the child table shouldn't affect the PK/FK mappings
at all unless you're trying to change the child table's FK/PK.  Weird.

These two sites suggest you need to check the version level of your
MySQL (for cascade support):
http://www.geocrawler.com/archives/3/8/2002/5/0/8813034/
http://www.riverside.org/archive/html/mysql/2003-02/msg00392.html

The order in which you declare the ON DELETE/ON UPDATE cascades may be
important:
http://www.faqchest.com/prgm/mysql-l/mysql-03/mysql-0302/mysql-030207/my
sql03020615_23303.html

Probably won't help, but maybe it will.

Tim
___ 
Tim Furry
Web Developer 
Foulston Siefkin LLP 




 • The WDVL Discussion List from WDVL.COM • 
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED]
   Send Your Posts To: [EMAIL PROTECTED]
To change subscription settings to the wdvltalk digest version:
http://wdvl.internet.com/WDVL/Forum/#sub

  http://www.wdvl.com  ___

You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]


[wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't update the child table - HELP

2003-03-18 Thread Paul Larue
Hi Sonja,
Thanks for the advice. I think I'll stick to it.

Regards
Paul

-Original Message-
From: Van Der Westhuizen, Sonja [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 18, 2003 11:39 PM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't
update the child table - HELP


Hi Paul,

You can't update or delete any information in a column if there is a pk/fk
mapping. SQL needs to maintain the integrity of the information and this is
one of the ways it does it. If you want to keep the group name in the
employees table why do you have the employees group at all. You need to
normalize your database as this is the way databases should be designed
(meaning splitting the employee information and the employee group
information with links to the id's). Therefore you need to set it up like
the example I gave you. Why do you want to avoid a union select? If it is
the same as MSSQL you would use a "LEFT JOIN employees.emp_groupid ON
employee_groups.grp_id" to get your information (this basically says include
all the records from employees to all the groups/id's that referenced in
employee_groups)

Just a note. I find this easier to work with.  If you have
employee_group.grp_id as the column name, use the same grp_id name in your
employees table.  Therefore if you go back at a later stage you know exactly
where what links to.

I hope this is clear
Sonja

-Original Message-
From: Paul Larue [mailto:[EMAIL PROTECTED]
Sent: 19 March 2003 04:13 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't
update the child table - HELP


Sonja,
I thought about that one but the result will be that if I want to have,
let's say, a list of employees and their associated groups, I would have to
make a UNION select on the 2 tables to get the associated
employee_groups.grp_name since employees.emp_group only contains the ID of
the group name. So only to avoid that, I would prefer to keep the actual
pk/fk mapping. Your solution is somehow interesting since updating
employee_groups.grp_name DOES NOT affect the employees table.

What do you think is better? Keep the existing setup and bang my head
against the wall to find out why it won't work or change to the one you
proposed? Taking into consideration the issue I pointed out above (the UNION
stuff).

Thanks

Paul

-Original Message-
From: Van Der Westhuizen, Sonja [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 18, 2003 5:35 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't
update the child table - HELP


Hi Paul,

I hope I understand correctly (little sleep can make you see things)...

In MSSQL when a record gets updated it "deletes" it first and then it
"inserts" the new information. To us it looks like it just updated the
information. So I assume it will happen the same in MySQL.  The reason you
cant update the record is becuase you "mapped" (setting up primary and
secondary key contraints - employees.emp_group and
employee_groups.grp_name). I suggest you rather set up your constraints
using employees.emp_group (make it an INTEGER) and employee_groups.grp_id.
That way if you want to update the group name you only have to do it in
employee_groups.grp_name.  While you are updating your employees table with
the group information you can drop the constraints and then activating it
again when you are finished. Im not quite sure what the MySQl commands for
that will be.

I hope this helps.
Sonja

-Original Message-
From: Paul Larue [mailto:[EMAIL PROTECTED]
Sent: 19 March 2003 02:29 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't
update the child table - HELP


Me again, Anybody can help?

Paul

-Original Message-
From: Paul Larue [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 20, 2003 9:58 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] [MySQL] InnoDB - Updating a parent table won't
update the child table


Hi all,
I created 2 tables in MySQl with the following statements
==
CREATE TABLE employees (
emp_id INT NOT NULL AUTO_INCREMENT,
emp_last_name TINYTEXT NOT NULL,
emp_first_name TINYTEXT NOT NULL,
emp_nick_name TINYTEXT NOT NULL,
emp_date_joined DATE NOT NULL,
emp_date_left DATE,
emp_title TINYTEXT NOT NULL,
emp_group CHAR(50),
emp_address TINYTEXT NOT NULL,
emp_city TINYTEXT NOT NULL,
emp_phone CHAR(7) NULL,
emp_mobile CHAR(7) NULL,
emp_national_id CHAR(14) NOT NULL,
emp_social_security CHAR(8) NOT NULL,
emp_tax_ac CHAR(8) NULL,
PRIMARY KEY (emp_id),
KEY (emp_group),
FOREIGN KEY (emp_group) REFERENCES employee_groups(grp_name)
ON DELETE SET NULL
ON UPDATE CASCADE
)
TY

[wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't update the child table - HELP

2003-03-18 Thread Van Der Westhuizen, Sonja
Hi Paul,

You can't update or delete any information in a column if there is a pk/fk
mapping. SQL needs to maintain the integrity of the information and this is
one of the ways it does it. If you want to keep the group name in the
employees table why do you have the employees group at all. You need to
normalize your database as this is the way databases should be designed
(meaning splitting the employee information and the employee group
information with links to the id's). Therefore you need to set it up like
the example I gave you. Why do you want to avoid a union select? If it is
the same as MSSQL you would use a "LEFT JOIN employees.emp_groupid ON
employee_groups.grp_id" to get your information (this basically says include
all the records from employees to all the groups/id's that referenced in
employee_groups)

Just a note. I find this easier to work with.  If you have
employee_group.grp_id as the column name, use the same grp_id name in your
employees table.  Therefore if you go back at a later stage you know exactly
where what links to. 

I hope this is clear
Sonja

-Original Message-
From: Paul Larue [mailto:[EMAIL PROTECTED]
Sent: 19 March 2003 04:13 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't
update the child table - HELP


Sonja,
I thought about that one but the result will be that if I want to have,
let's say, a list of employees and their associated groups, I would have to
make a UNION select on the 2 tables to get the associated
employee_groups.grp_name since employees.emp_group only contains the ID of
the group name. So only to avoid that, I would prefer to keep the actual
pk/fk mapping. Your solution is somehow interesting since updating
employee_groups.grp_name DOES NOT affect the employees table.

What do you think is better? Keep the existing setup and bang my head
against the wall to find out why it won't work or change to the one you
proposed? Taking into consideration the issue I pointed out above (the UNION
stuff).

Thanks

Paul

-Original Message-
From: Van Der Westhuizen, Sonja [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 18, 2003 5:35 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't
update the child table - HELP


Hi Paul,

I hope I understand correctly (little sleep can make you see things)...

In MSSQL when a record gets updated it "deletes" it first and then it
"inserts" the new information. To us it looks like it just updated the
information. So I assume it will happen the same in MySQL.  The reason you
cant update the record is becuase you "mapped" (setting up primary and
secondary key contraints - employees.emp_group and
employee_groups.grp_name). I suggest you rather set up your constraints
using employees.emp_group (make it an INTEGER) and employee_groups.grp_id.
That way if you want to update the group name you only have to do it in
employee_groups.grp_name.  While you are updating your employees table with
the group information you can drop the constraints and then activating it
again when you are finished. Im not quite sure what the MySQl commands for
that will be.

I hope this helps.
Sonja

-Original Message-
From: Paul Larue [mailto:[EMAIL PROTECTED]
Sent: 19 March 2003 02:29 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't
update the child table - HELP


Me again, Anybody can help?

Paul

-Original Message-
From: Paul Larue [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 20, 2003 9:58 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] [MySQL] InnoDB - Updating a parent table won't
update the child table


Hi all,
I created 2 tables in MySQl with the following statements
==
CREATE TABLE employees (
emp_id INT NOT NULL AUTO_INCREMENT,
emp_last_name TINYTEXT NOT NULL,
emp_first_name TINYTEXT NOT NULL,
emp_nick_name TINYTEXT NOT NULL,
emp_date_joined DATE NOT NULL,
emp_date_left DATE,
emp_title TINYTEXT NOT NULL,
emp_group CHAR(50),
emp_address TINYTEXT NOT NULL,
emp_city TINYTEXT NOT NULL,
emp_phone CHAR(7) NULL,
emp_mobile CHAR(7) NULL,
emp_national_id CHAR(14) NOT NULL,
emp_social_security CHAR(8) NOT NULL,
emp_tax_ac CHAR(8) NULL,
PRIMARY KEY (emp_id),
KEY (emp_group),
FOREIGN KEY (emp_group) REFERENCES employee_groups(grp_name)
ON DELETE SET NULL
ON UPDATE CASCADE
)
TYPE=InnoDB
COMMENT="Stores information about employees in company"

CREATE TABLE employee_groups (
grp_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
grp_name CHAR(50) NOT NULL,
grp_overtime_paid BOOL NOT NULL,
PRIMARY KEY (grp_id),
INDEX (grp_name))
TYPE=InnoDB
COMMENT="S

[wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't update the child table - HELP

2003-03-18 Thread Paul Larue
Sonja,
I thought about that one but the result will be that if I want to have,
let's say, a list of employees and their associated groups, I would have to
make a UNION select on the 2 tables to get the associated
employee_groups.grp_name since employees.emp_group only contains the ID of
the group name. So only to avoid that, I would prefer to keep the actual
pk/fk mapping. Your solution is somehow interesting since updating
employee_groups.grp_name DOES NOT affect the employees table.

What do you think is better? Keep the existing setup and bang my head
against the wall to find out why it won't work or change to the one you
proposed? Taking into consideration the issue I pointed out above (the UNION
stuff).

Thanks

Paul

-Original Message-
From: Van Der Westhuizen, Sonja [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 18, 2003 5:35 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't
update the child table - HELP


Hi Paul,

I hope I understand correctly (little sleep can make you see things)...

In MSSQL when a record gets updated it "deletes" it first and then it
"inserts" the new information. To us it looks like it just updated the
information. So I assume it will happen the same in MySQL.  The reason you
cant update the record is becuase you "mapped" (setting up primary and
secondary key contraints - employees.emp_group and
employee_groups.grp_name). I suggest you rather set up your constraints
using employees.emp_group (make it an INTEGER) and employee_groups.grp_id.
That way if you want to update the group name you only have to do it in
employee_groups.grp_name.  While you are updating your employees table with
the group information you can drop the constraints and then activating it
again when you are finished. Im not quite sure what the MySQl commands for
that will be.

I hope this helps.
Sonja

-Original Message-
From: Paul Larue [mailto:[EMAIL PROTECTED]
Sent: 19 March 2003 02:29 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't
update the child table - HELP


Me again, Anybody can help?

Paul

-Original Message-
From: Paul Larue [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 20, 2003 9:58 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] [MySQL] InnoDB - Updating a parent table won't
update the child table


Hi all,
I created 2 tables in MySQl with the following statements
==
CREATE TABLE employees (
emp_id INT NOT NULL AUTO_INCREMENT,
emp_last_name TINYTEXT NOT NULL,
emp_first_name TINYTEXT NOT NULL,
emp_nick_name TINYTEXT NOT NULL,
emp_date_joined DATE NOT NULL,
emp_date_left DATE,
emp_title TINYTEXT NOT NULL,
emp_group CHAR(50),
emp_address TINYTEXT NOT NULL,
emp_city TINYTEXT NOT NULL,
emp_phone CHAR(7) NULL,
emp_mobile CHAR(7) NULL,
emp_national_id CHAR(14) NOT NULL,
emp_social_security CHAR(8) NOT NULL,
emp_tax_ac CHAR(8) NULL,
PRIMARY KEY (emp_id),
KEY (emp_group),
FOREIGN KEY (emp_group) REFERENCES employee_groups(grp_name)
ON DELETE SET NULL
ON UPDATE CASCADE
)
TYPE=InnoDB
COMMENT="Stores information about employees in company"

CREATE TABLE employee_groups (
grp_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
grp_name CHAR(50) NOT NULL,
grp_overtime_paid BOOL NOT NULL,
PRIMARY KEY (grp_id),
INDEX (grp_name))
TYPE=InnoDB
COMMENT="Stores group names and their properties"
==
The field employee_groups.grp_name is 'mapped' to employees.emp_group and
the referential integrity is set all the associated fileds to NULL when the
parent record is DLETED and to CASCADE when the parent record is UPDATED.

Creating the tables is fine. Inserting data in the tables is fine too. But
when I try to update a record in employee_groups, MySQL returns the
following error

mysql> UPDATE employee_groups SET grp_name = "FOO" WHERE grp_id = 1;
ERROR 1217: Cannot delete a parent row: a foreign key constraint fails

Why is it telling me that I'm trying to delete the record when I'm only
doing a simple update?

Deleting the records is ok, MySQl sets the associated fields to NULL. But
the update WON'T work...

Any clue?

Thanks in advance

Paul



 * The WDVL Discussion List from WDVL.COM * 
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED]
   Send Your Posts To: [EMAIL PROTECTED]
To change subscription settings to the wdvltalk digest version:
http://wdvl.internet.com/WDVL/Forum/#sub

  http://www.wdvl.com  ___

You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to %%email.unsub%%



 * The W

[wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't update the child table - HELP

2003-03-18 Thread Van Der Westhuizen, Sonja
Hi Paul,

I hope I understand correctly (little sleep can make you see things)...

In MSSQL when a record gets updated it "deletes" it first and then it
"inserts" the new information. To us it looks like it just updated the
information. So I assume it will happen the same in MySQL.  The reason you
cant update the record is becuase you "mapped" (setting up primary and
secondary key contraints - employees.emp_group and
employee_groups.grp_name). I suggest you rather set up your constraints
using employees.emp_group (make it an INTEGER) and employee_groups.grp_id.
That way if you want to update the group name you only have to do it in
employee_groups.grp_name.  While you are updating your employees table with
the group information you can drop the constraints and then activating it
again when you are finished. Im not quite sure what the MySQl commands for
that will be.

I hope this helps. 
Sonja

-Original Message-
From: Paul Larue [mailto:[EMAIL PROTECTED]
Sent: 19 March 2003 02:29 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't
update the child table - HELP


Me again, Anybody can help?

Paul

-Original Message-
From: Paul Larue [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 20, 2003 9:58 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] [MySQL] InnoDB - Updating a parent table won't
update the child table


Hi all,
I created 2 tables in MySQl with the following statements
==
CREATE TABLE employees (
emp_id INT NOT NULL AUTO_INCREMENT,
emp_last_name TINYTEXT NOT NULL,
emp_first_name TINYTEXT NOT NULL,
emp_nick_name TINYTEXT NOT NULL,
emp_date_joined DATE NOT NULL,
emp_date_left DATE,
emp_title TINYTEXT NOT NULL,
emp_group CHAR(50),
emp_address TINYTEXT NOT NULL,
emp_city TINYTEXT NOT NULL,
emp_phone CHAR(7) NULL,
emp_mobile CHAR(7) NULL,
emp_national_id CHAR(14) NOT NULL,
emp_social_security CHAR(8) NOT NULL,
emp_tax_ac CHAR(8) NULL,
PRIMARY KEY (emp_id),
KEY (emp_group),
FOREIGN KEY (emp_group) REFERENCES employee_groups(grp_name)
ON DELETE SET NULL
ON UPDATE CASCADE
)
TYPE=InnoDB
COMMENT="Stores information about employees in company"

CREATE TABLE employee_groups (
grp_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
grp_name CHAR(50) NOT NULL,
grp_overtime_paid BOOL NOT NULL,
PRIMARY KEY (grp_id),
INDEX (grp_name))
TYPE=InnoDB
COMMENT="Stores group names and their properties"
==
The field employee_groups.grp_name is 'mapped' to employees.emp_group and
the referential integrity is set all the associated fileds to NULL when the
parent record is DLETED and to CASCADE when the parent record is UPDATED.

Creating the tables is fine. Inserting data in the tables is fine too. But
when I try to update a record in employee_groups, MySQL returns the
following error

mysql> UPDATE employee_groups SET grp_name = "FOO" WHERE grp_id = 1;
ERROR 1217: Cannot delete a parent row: a foreign key constraint fails

Why is it telling me that I'm trying to delete the record when I'm only
doing a simple update?

Deleting the records is ok, MySQl sets the associated fields to NULL. But
the update WON'T work...

Any clue?

Thanks in advance

Paul



 * The WDVL Discussion List from WDVL.COM * 
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED]
   Send Your Posts To: [EMAIL PROTECTED]
To change subscription settings to the wdvltalk digest version:
http://wdvl.internet.com/WDVL/Forum/#sub

  http://www.wdvl.com  ___

You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to %%email.unsub%%



 * The WDVL Discussion List from WDVL.COM * 
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] 
   Send Your Posts To: [EMAIL PROTECTED]
To change subscription settings to the wdvltalk digest version:
http://wdvl.internet.com/WDVL/Forum/#sub

  http://www.wdvl.com  ___

You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to %%email.unsub%%

___


The views expressed in this email are, unless otherwise stated, those of the author 
and not those
of the FirstRand Banking Group or its management.  The information in this e-mail is 
confidential
and is intended solely for the addressee. Access to this e-mail by anyone else is 
unauthorised. 
If you are not the intended recipient, any disclosure, copying, distribution or any 
action taken or 
omitted in reliance on this, is prohibited and may be un

[wdvltalk] RE: [MySQL] InnoDB - Updating a parent table won't update the child table - HELP

2003-03-18 Thread Paul Larue
Me again, Anybody can help?

Paul

-Original Message-
From: Paul Larue [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 20, 2003 9:58 AM
To: [EMAIL PROTECTED]
Subject: [wdvltalk] [MySQL] InnoDB - Updating a parent table won't
update the child table


Hi all,
I created 2 tables in MySQl with the following statements
==
CREATE TABLE employees (
emp_id INT NOT NULL AUTO_INCREMENT,
emp_last_name TINYTEXT NOT NULL,
emp_first_name TINYTEXT NOT NULL,
emp_nick_name TINYTEXT NOT NULL,
emp_date_joined DATE NOT NULL,
emp_date_left DATE,
emp_title TINYTEXT NOT NULL,
emp_group CHAR(50),
emp_address TINYTEXT NOT NULL,
emp_city TINYTEXT NOT NULL,
emp_phone CHAR(7) NULL,
emp_mobile CHAR(7) NULL,
emp_national_id CHAR(14) NOT NULL,
emp_social_security CHAR(8) NOT NULL,
emp_tax_ac CHAR(8) NULL,
PRIMARY KEY (emp_id),
KEY (emp_group),
FOREIGN KEY (emp_group) REFERENCES employee_groups(grp_name)
ON DELETE SET NULL
ON UPDATE CASCADE
)
TYPE=InnoDB
COMMENT="Stores information about employees in company"

CREATE TABLE employee_groups (
grp_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
grp_name CHAR(50) NOT NULL,
grp_overtime_paid BOOL NOT NULL,
PRIMARY KEY (grp_id),
INDEX (grp_name))
TYPE=InnoDB
COMMENT="Stores group names and their properties"
==
The field employee_groups.grp_name is 'mapped' to employees.emp_group and
the referential integrity is set all the associated fileds to NULL when the
parent record is DLETED and to CASCADE when the parent record is UPDATED.

Creating the tables is fine. Inserting data in the tables is fine too. But
when I try to update a record in employee_groups, MySQL returns the
following error

mysql> UPDATE employee_groups SET grp_name = "FOO" WHERE grp_id = 1;
ERROR 1217: Cannot delete a parent row: a foreign key constraint fails

Why is it telling me that I'm trying to delete the record when I'm only
doing a simple update?

Deleting the records is ok, MySQl sets the associated fields to NULL. But
the update WON'T work...

Any clue?

Thanks in advance

Paul



 • The WDVL Discussion List from WDVL.COM • 
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED]
   Send Your Posts To: [EMAIL PROTECTED]
To change subscription settings to the wdvltalk digest version:
http://wdvl.internet.com/WDVL/Forum/#sub

  http://www.wdvl.com  ___

You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to %%email.unsub%%



 • The WDVL Discussion List from WDVL.COM • 
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] 
   Send Your Posts To: [EMAIL PROTECTED]
To change subscription settings to the wdvltalk digest version:
http://wdvl.internet.com/WDVL/Forum/#sub

  http://www.wdvl.com  ___

You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]