Very nice But what should I asgin the colmun that I intend to put as a foreign key for another table .....a Primary key, index or unique key ?!
Main Topics
Browse All TopicsHi ALL;
How to set up a foreign key to a table in MySQL using phpMyAdmin ( 2.9.2 )?
Please help
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Create an index on the field you want to use for foreign key constraint.
Then when you click on Relation view you will have 3 text boxes with the field(s) you want to use.
Lets suppose you have a table name Customer with a field name invoice_id, you also have a table named Invoice with the primary field named invoice_id.
If you open Relation view on Customer you will see a list of all the fields in that table at the top yu will see
Links to
invoice_id [drop down with the list of all the table fields you can link to] ON DELETE [drop down with the options Cascade
SET NULL
NO ACTION
RESTRICT]
ON UPDATE [drop down with the same options]
So you could setup that the invoice will be deleted if you delete the customer link to it [cascade]
I don't know how complex is your application but this is the basic on how to set the foreign key with phpmyadmin
Ok great this is what I'm doing ...
BUT after creating an index for invoice_id field in Customer table and then choosing
invoice_id [Invoice->invoice_id] ON DELETE [Cascade]ON UPDATE [Cascade]
And then press Save
I got this error messege in red at the top of the page
No index defined! ( invoice_id)
So what I did wrong?!!
Business Accounts
Answer for Membership
by: gamebitsPosted on 2007-10-09 at 07:50:53ID: 20041424
1) You need a table set with InnoDB (MyISAM does not support foreign key constraint)
2) Click on the Structure tab.
3) Under the table shown there is a link "Relation View"
4) That's where you set up the constraint.