I am using mysql 4.2. I have a big database with lots of data. Now there is no foreign key relationship between the tables. But every one has a primary key. Can I alter these tables to bring foreign key without affecting the data? Thanx in advance....
Add foreign key to existing tables
Collapse
X
-
Some of them are MyISAM and some are InnoDB...what I have to do?Originally posted by pbmodsHeya, AMT.
Are these tables MyISAM or InnoDB?
If you're not sure, try issuing a [code=mysql]SHOW CREATE TABLE `tableName`\G[/code].
Look for ENGINE=MyISAM or ENGINE=InnoDB.Comment
-
Heya, AMT.
Only InnoDB tables properly support foreign key constraints right now. You can change the storage engine for any table by executing this command:
[code=mysql]
ALTER TABLE `tableName` ENGINE=InnoDB;
[/code]
MyISAM is faster, especially for large data sets, than InnoDB. The trade-off is that MyISAM does not support row locking, transactions nor foreign key constraints.
Check out this document for more information on setting up foreign key constraints on an InnoDB table.Comment
-
Ok..i will change tables to InnoDB. But can I add foreign key for a table which contains data?Originally posted by pbmodsHeya, AMT.
Only InnoDB tables properly support foreign key constraints right now. You can change the storage engine for any table by executing this command:
[code=mysql]
ALTER TABLE `tableName` ENGINE=InnoDB;
[/code]
MyISAM is faster, especially for large data sets, than InnoDB. The trade-off is that MyISAM does not support row locking, transactions nor foreign key constraints.
Check out this document for more information on setting up foreign key constraints on an InnoDB table.Comment
Comment