Hi! At 12:24 PM 12/13/01 -0800, you wrote: >Heikki Tuuri wrote: > >> Foreign keys do not work if you do an ALTER TABLE. I have to add a note to >> the manual that they do not work even if you do an ALTER TABLE to the >> referenced table. > > >Are you saying that you can't add columns to a table (to grow the schema >incrementally between software versions) without losing all your >foreign-key constraints? Or having to dump and restore databases each time?
ALTER TABLE actually in MySQL does a dump and restore. It creates a new table where it imports the data from the original table, then it renames the original table, renames the new table, and drops the original table. To preserve your foreign key constraints, you must do this DROP TABLE + CREATE TABLE currently manually, do not use ALTER TABLE. >Would it work to drop and recreate all the foreign-key constraints after >each alter table? But InnoDB does not currently support an ALTER TABLE where you add a new foreign key constraint. Note that the CREATE TABLE statements which execute are a part of your database application source code, just like the C, Perl, or PHP code you write. It is good coding practice to always keep track of what CREATE TABLE statements are needed to create your database schema. >-- >Shankar. Regards, Heikki Innobase Oy --- See http://www.innodb.com for the latest news about InnoDB Order commercial MySQL/InnoDB support at https://order.mysql.com/ --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php