doubledee — 2011-01-29T13:04:54-05:00 — #1
When you have a "parent" and a "child" table, do you have to create the "parent" table before the "child" table?
It seems like you have to create the "parent" first so the "child" will have something to return to. :-/
r937 — 2011-01-29T13:22:05-05:00 — #2
you must declare the referenced table before referencing it in a FOREIGN KEY declaration (in an engine which supports foreign keys)
i'm not sure whether disabling the foreign key check will disable it during the CREATE TABLE statement, though (disabling foreign key checking is usually done when loading large volumes of data, to minimize the overhead of checking individual rows)
still, it makes sense to create your tables in the intended order anyway
doubledee — 2011-01-29T13:43:04-05:00 — #3
So that was a "Yes"??
r937 — 2011-01-29T14:11:43-05:00 — #4
depending on what you mean by "return to"
doubledee — 2011-01-29T14:50:30-05:00 — #5
So the child table will have something to REFER (i.e. point) to.
oddz — 2011-01-29T17:04:57-05:00 — #6
If you are using an engine that supports foreign key constraints and using them than yes, you will need to create the table referenced by the foreign key relationship first. If you are creating "conceptual" foreign keys, but not actually enforcing them with TRUE constraints than no, you don't NEED to create the referenced table first but you should. Create a INNODB table with a foreign key constraint with a reference to a table that doesn't exist. Than do the same thing with a MYISAM table minus the foreign key constraint and see what happens.