Table types in MySQL
In MySQL, what table type is required for foreign keys to work?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Arjun PanwarPosted Nov 25, 2011, 3:09 AM
AartiPosted Nov 24, 2011, 5:06 AM
InnoDB supports foreign key constraints.
The syntax for a foreign key constraint definition in InnoDB looks like this:
[CONSTRAINT [symbol]] FOREIGN KEY
[index_name] (index_col_name, ...)
REFERENCES tbl_name (index_col_name,...)
[ON DELETE reference_option]
[ON UPDATE reference_option]
reference_option:
RESTRICT | CASCADE | SET NULL | NO ACTION
Foreign keys definitions are subject to the following conditions:
1.Both tables must be InnoDB tables and they must not be TEMPORARY tables.
2. Corresponding columns in the foreign key and the referenced key must have similar internal data types inside InnoDB so that they can be compared without a type conversion.
The size and sign of integer types must be the same. The length of string types need not be the same.
For nonbinary (character) string columns, the character set and collation must be the same.
3.InnoDB requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan.
In the referencing table, there must be an index where the foreign key columns are listed as the first columns in the same order.
Such an index is created on the referencing table automatically if it does not exist.
(This is in contrast to some older versions, in which indexes had to be created explicitly or the creation of foreign key constraints would fail.) index_name, if given, is used as described previously.
4.InnoDB permits a foreign key to reference any index column or group of columns.
However, in the referenced table, there must be an index where the referenced columns are listed as the first columns in the same order.
5.Index prefixes on foreign key columns are not supported. One consequence of this is that BLOB and TEXT columns cannot be included in a foreign key because indexes on those columns must always include a prefix length.
6.If the CONSTRAINT symbol clause is given, the symbol value must be unique in the database. If the clause is not given, InnoDB creates the name automatically
Satyapriya NayakPosted Nov 24, 2011, 4:26 AM
InnoDBsupports foreign key constraints.Refer
http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html
http://www.techrepublic.com/article/an-introduction-to-foreign-keys-and-referential-integrity-in-mysql/6035435
Thanks