Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Foreign Keys and Referential Integrity
Old 06-01-2005, 08:51 PM Foreign Keys and Referential Integrity
Novice Talker

Posts: 8
Trades: 0
I have two tables like this:

CREATE TABLE parent
(
par_id INT NOT NULL,
PRIMARY KEY (par_id)
) ENGINE = INNODB;

CREATE TABLE child
(
par_id INT NOT NULL,
child_id INT NOT NULL,
PRIMARY KEY (par_id, child_id),
FOREIGN KEY (par_id) REFERENCES parent (par_id)
ON DELETE CASCADE
ON UPDATE CASCADE
) ENGINE = INNODB;

When I delete anything from the parent table, it deletes everything related to the parent table. This is OK.

But when I delete anything from the child table, it does delete it.
It was not supposed to because the foreing key.

What do I need to do to only be able to delete from the parent table?
I would like to have a message saying that record can not delete because thats a child table.

Thanks
Roger.
rogernem is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-02-2005, 03:24 AM
Marvin Le Rouge's Avatar
Skilled Talker

Posts: 52
Trades: 0
Why shouldn't it be supposed to delete the data ? You can delete lines in child when you have a foreign key constraint. Example : you have a clothing store, with a shirts section : you can stop selling one shirt model, this does not delete the entire section : shirts still exist.
What is forbidden is to delete only par_id, for it references the parent, and should not be null.
I do not think there is a "normal" way to forbid deletion from child table.
Marvin Le Rouge is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Foreign Keys and Referential Integrity
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.43369 seconds with 12 queries