In what order are ON DELETE CASCADE constraints processed?

后端 未结 4 922
失恋的感觉
失恋的感觉 2021-01-02 05:20

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         


        
4条回答
  •  被撕碎了的回忆
    2021-01-02 06:22

    the design is all wrong. You should have single table, with parent child relationship (literrally). Then you can figure out uncles (and aunts) with a query

    select id from persons where -find all children of the grandparents
    parent id in (
    select parentid from persons --find the grandparents
    where id in (
    select parentid from persons --find the parents
    where id=THECHILD) )
    minus --and take out the child's parents
    select parentid from persons
    where id=THECHILD

提交回复
热议问题