hawkeye
hawkeye

Reputation: 349

Setting foreign key in phpMyAdmin

I want to make namecon of table "paper" as a foreign key reference to table "journal" to its primary key jname. I am getting confused with this view and not finding any tutorial or link which is explaining to set foreign key with this schema of phpMyAdmin. (Is it new or what) Please someone let me to figure this out.

This is how the relation looks like

Upvotes: 0

Views: 1215

Answers (2)

hawkeye
hawkeye

Reputation: 349

While making the foreign key, it is also advisable to mark the index key option available int Structure view of the table. That will make the primary key thing to visible in the relational view of that particular table which can be used for making foreign key.

Upvotes: 0

Isaac Bennetch
Isaac Bennetch

Reputation: 12412

First, you need to create an index on the namecon column, click on the Structure tab ("Table structure" sub-heading on newer phpMyAdmin versions), then the Index text for the namecon column. You also need an index on the jname column in your journal table; in most of my databases this is an auto incrementing primary key but all that MySQL requires is that it's an index.

Next, go back to the Relation View (which is a sub-heading of Structure under newer versions). Note that this is in the area for "Foreign key constraints" not "Internal relations." Now you'll be able to select namecon from the "Column" dropdown:

Relations dialog box

If you want you can give it a name, otherwise MySQL generates one for you.

Upvotes: 1

Related Questions