MySQL on delete cascade. Test Example

后端 未结 2 1714
谎友^
谎友^ 2020-12-01 12:32

I am wondering about this test question. I prepared the example myself and tested it but I still feel unsure of the answer.

With the following:

CREAT         


        
2条回答
  •  情书的邮戳
    2020-12-01 12:47

    Answer d. is correct, if and only if the storage engine actually supports and enforces foreign key constraints.

    If the tables are created with Engine=MyISAM, then neither b. or d. is correct.

    If the tables are created with Engine=InnoDB, then d. is correct.

    NOTE:

    This is true for InnoDB if and only if FOREIGN_KEY_CHECKS = 1; if FOREIGN_KEY_CHECKS = 0, then a DELETE from the parent table (foo) will not remove rows from the child table (foo2) that reference a row removed from the parent table.

    Verify this with the output from SHOW VARIABLES LIKE 'foreign_key_checks' (1=ON, 0=OFF) (The normal default is for this to be ON.)

    The output from SHOW CREATE TABLE foo will show which engine the table uses.

    The output from SHOW VARIABLES LIKE 'storage_engine' will show the default engine used when a table is created and the engine is not specified.

提交回复
热议问题