in Education by
Here is an example of what I've got going on: CREATE TABLE Parent (id BIGINT NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB; CREATE TABLE Child (id BIGINT NOT NULL, parentid BIGINT NOT NULL, PRIMARY KEY (id), KEY (parentid), CONSTRAINT fk_parent FOREIGN KEY (parentid) REFERENCES Parent (id) ON DELETE CASCADE) ENGINE=InnoDB; CREATE TABLE Uncle (id BIGINT NOT NULL, parentid BIGINT NOT NULL, childid BIGINT NOT NULL, PRIMARY KEY (id), KEY (parentid), KEY (childid), CONSTRAINT fk_parent_u FOREIGN KEY (parentid) REFERENCES Parent (id) ON DELETE CASCADE, CONSTRAINT fk_child FOREIGN KEY (childid) REFERENCES Child (id)) ENGINE=InnoDB; Notice there is no ON DELETE CASCADE for the Uncle-Child relationship; i.e. deleting a Child does not delete its Uncle(s) and vice-versa. When I have a Parent and an Uncle with the same Child, and I delete the Parent, it seems like InnoDB should be able to just "figure it out" and let the cascade ripple through the whole family (i.e. deleting the Parent deletes the Uncle and the Child as well). However, instead, I get the following: ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`cascade_test/uncle`, CONSTRAINT `fk_child` FOREIGN KEY (`childid`) REFERENCES `child` (`id`)) InnoDB is trying to cascade-delete the Child before the Uncle(s) that refer to it. Am I missing something? Is this supposed to fail for some reason I don't understand? Or is there some trick to making it work (or is it a bug in MySQL)? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
In the simpler case, what happens if a record is deleted from Child and it has a referencing Uncle? That's unspecified, so the constraints fail for that anyway. If deleting a Child does not delete its Uncles, then what happens instead? Uncle.childid cannot be null. What you want is one of these three things: Uncle.childid can be null, and you want ON DELETE SET NULL for childid. Uncle.childid cannot be null, and you want ON DELETE CASCADE for childid. Childid does not belong on Uncle, and you want a ChildsUncle relation with ON DELETE CASCADE foreign key constraints to both Child and Uncle. Uncleid would be a candidate key for that relation (i.e. it should be unique).

Related questions

0 votes
    I have a problem with Hibernate. In Short: How to configure a ManyToMany association with Hibernate when the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 21, 2022 in Education by JackTerrance
0 votes
    f. Use the following formula to output the variable on the left: Cascade the cout statements Use the following variations ... (v) E=mc Select the correct answer from above options...
asked Dec 29, 2021 in Education by JackTerrance
0 votes
    I have the following table relationship in my database: Parent / \ Child1 Child2 \ / GrandChild I am ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I am facing a problem that makes me to waste a lot of time. Each time I insert an element on a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    I am facing a problem that makes me to waste a lot of time. Each time I insert an element on a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 10, 2022 in Education by JackTerrance
0 votes
    The general idea of field _________ is to set rules or constraints on what data can be entered in data field. Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    The general idea of field _________ is to set rules or constraints on what data can be entered in data field. Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    The functional dependency can be tested easily on the materialized view, using the constraints ____________. ... for Decomposition in portion Normalization of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    What will happen if two thread of the same priority are called to be processed simultaneously? (a) Anyone ... Multithreading of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Symfony version: 3.1.3 Due to development reason suddenly my app giving the following error and I believe ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    I have an issue while building my Solr index (Lucene & Solr 3.4.0 on an Apache Tomcat 6.0.33) ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Raw data should be processed only one time. (a) True (b) False The question was asked in an interview ... questions and answers pdf, Data Science interview questions for beginners...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    Which of the following is characteristic of Processed Data? (a) Data is not ready for analysis (b) All ... questions and answers pdf, Data Science interview questions for beginners...
asked Oct 28, 2021 in Education by JackTerrance
...