Database Reference
In-Depth Information
In the possible choices for the related key, we see the keys defined in all the InnoDB
tables of the same database. (Creating a cross-database relation is currently not
supported in phpMyAdmin.) We even see the keys defined in the current table, as
self-referring relations are possible. We now remove the internal relation for the
author_id
field and click
Save
. We would like to add an InnoDB-type relation for the
author_id
field, but we cannot. We see the
No index defined!
message on this line.
This is because foreign key definitions in InnoDB or PBXT can be done only if both
the fields are defined as indexes.
Other conditions regarding constraints are explained in the MySQL
manual. Please refer to
http://dev.mysql.com/doc/refman/5.0/
en/innodb-foreign-key-constraints.html
.
Thus, we come back to the
Structure
page for the
book
table and add an ordinary
(non-unique) index to the
author_id
field producing:
In the
Relation view
, we can try again to add the relation we wanted; it works
this time!
We can also set some actions with the
ON DELETE
and
ON UPDATE
options. For
example,
ON DELETE CASCADE
would make MySQL automatically delete all the
rows in the related (foreign) table when the corresponding row is deleted from the
parent table. This would be useful, for example, when the parent table is
invoices
,
and the foreign table is
invoice-items
.
Search WWH ::
Custom Search