MySQL 如何更改 phpMyAdmin 中的外键

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10390397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:12:12  来源:igfitidea点击:

How to alter Foreign Keys in phpMyAdmin

mysqlforeign-keys

提问by Rewind

I have set up a Foreign Key in my mysql database with:

我已经在我的 mysql 数据库中设置了一个外键:

ALTER TABLE `gameplayers` ADD CONSTRAINT `FK_GAMENUMBER` FOREIGN KEY (`GameNumber`) REFERENCES `games`(`GameNumber`) ON UPDATE CASCADE ON DELETE CASCADE;

However, I am not sure I want the ON UPDATE and ON DELETE anymore.

但是,我不确定我是否想要 ON UPDATE 和 ON DELETE 了。

So I go into my phpAdmin, click on the edit pencil icon in the Index section of the Structure Tab and I get this:

因此,我进入我的 phpAdmin,单击“结构”选项卡的“索引”部分中的编辑铅笔图标,然后得到以下信息:

Warning: ("PRIMARY" must be the name of and only of a primary key!)

警告:(“PRIMARY”必须是主键的名称并且只能是主键的名称!)

Do alterations just have to be done manually? Ie the pencil icon will just not work.

更改是否只需要手动完成?即铅笔图标将不起作用。

ALSO: Do foreign keys have the same speed bonus effect on mysql searches, similar to Indexes?

ALSO: 外键对 mysql 搜索是否有相同的速度加成效果,类似于索引?

回答by Maxim Krizhanovsky

Foreign keys require indexes, so effectively, the foreign key constrain creates and index and it can be used to resolve queries just like normal indexes.

外键需要索引,因此有效地,外键约束创建和索引,它可以像普通索引一样用于解析查询。

I'm not sure which version of phpMyAdmin you are using, I think foreign key constains are supported in newest versions, but it seems your does not list foreign key indexes, and the primary key is not what you are looking for. You can however modify the keys with plain SQL:

我不确定您使用的是哪个版本的 phpMyAdmin,我认为最新版本支持外键包含,但您似乎没有列出外键索引,并且主键不是您要查找的。但是,您可以使用纯 SQL 修改键:

ALTER TABLE `gameplayers` DROP FOREIGN KEY FK_GAMENUMBER,
    ADD CONSTRAINT `FK_GAMENUMBER` FOREIGN KEY (`GameNumber`) REFERENCES `games`(`GameNumber`) ON UPDATE NO ACTION ON DELETE NO ACTION;