简体   繁体   English

在phpMyAdmin中设置外键

[英]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 . 我想将表“ paper”的 namecon用作对表“ journal”的主键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. 我对此视图感到困惑,没有找到任何教程或链接来解释使用phpMyAdmin的这种模式设置外键。 (Is it new or what) Please someone let me to figure this out. (是新的还是什么)请有人让我弄清楚。

这就是关系的样子

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. 首先,您需要在namecon列上创建索引,单击“结构”选项卡(在较新的phpMyAdmin版本上为“表结构”子标题),然后单击namecon列的Index文本。 You also need an index on the jname column in your journal table; 您还需要在journal表的jname列上建立索引。 in most of my databases this is an auto incrementing primary key but all that MySQL requires is that it's an index. 在我的大多数数据库中,这是一个自动递增的主键,但是MySQL所需要的只是它是一个索引。

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: 现在,您可以从“列”下拉列表中选择namecon:

关系对话框

If you want you can give it a name, otherwise MySQL generates one for you. 如果愿意,可以给它起一个名字,否则MySQL会为您生成一个名字。

While making the foreign key, it is also advisable to mark the index key option available int Structure view of the table. 在制作外键时,建议将索引键选项标记为int在表的“结构”视图中可用。 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. 这将使主键在该特定表的关系视图中可见,该表可用于制作外键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM