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:
CREATE TABLE foo (
id INT PRIMARY KEY AUTO_INCREMENT,
name INT
)
CREATE TABLE foo2 (
id INT PRIMARY KEY AUTO_INCREMENT,
foo_id INT REFERENCES foo(id) ON DELETE CASCADE
)
As far as I can see the answer is:
a. Two tables are created
Although there are also:
b. If a row in table foo2, with a foo_id of 2 is deleted, then the row with id=2 in the table foo is automatically deleted
d.If a row with id = 2 in table foo is deleted, all rows with foo_id = 2 in table foo2 are deleted
In my example I would have used the delete syntax:
DELETE FROM foo WHERE id = 2;
DELETE FROM foo2 WHERE foo_id = 2;
For some reason I was unable to find any relationship between the tables although it seems like there should be one. Maybe there is some MySQL setting or perhaps is ON DELETE CASCADE
not used properly in the table creation queries? I am left wondering...