A little SQL brain teaser

What happens to record in D when you delete from A? Which takes precedence, cascade or restrict?

Scroll down for the answer.

Here’s the script:

The answer is …

The transaction fails. Restrict has precedence over cascade.

ERROR 1451 (23000) at line 38 in file: 'tmp/scratch.sql': Cannot delete or update a parent row: a foreign key constraint fails (`test_fkc`.`d`, CONSTRAINT `d_ibfk_2` FOREIGN KEY (`c_id`) REFERENCES `c` (`id`))

Tested in MariaDB 10.2.5

Show your support

Clapping shows how much you appreciated Jared Beck’s story.