gpt4 book ai didi

mysql - 重命名唯一键名 MySQL

转载 作者:行者123 更新时间:2023-11-29 04:16:31 25 4
gpt4 key购买 nike

我有一个列有一个 UNIQUE KEY ExtendedOrderID

我将此列重命名为 OrderLineItemID

仍然,当我转到 SHOW CREATE TABLE 时,它正在说明

. . . 
UNIQUE KEY `ExtendedOrderID` (`OrderLineItemID`)
. . . ) ENGINE=InnoDB . . .

显示我原来的列名。

现在,我认为这不会影响任何事情,因为它仍然指向正确命名的新列 OrderLineItemID,但是我如何从表格并将其重命名以正确显示

UNIQUE KEY `OrderLineItemID` (`OrderLineItemID`)

最佳答案

您可以使用 ALTER TABLE 命令中的 RENAME INDEX 子句重命名它(自 MySQL 5.7 起)。

来自documentation :

RENAME INDEX old_index_name TO new_index_name renames an index. This is a MySQL extension to standard SQL. The content of the table remains unchanged. old_index_name must be the name of an existing index in the table that is not dropped by the same ALTER TABLE statement. new_index_name is the new index name, which cannot duplicate the name of an index in the resulting table after changes have been applied. Neither index name can be PRIMARY.

ALTER TABLE my_table RENAME INDEX ExtendedOrderID TO OrderLineItemID;

关于mysql - 重命名唯一键名 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42965946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com