簡體   English   中英

mysql更改約束名稱,怎么樣?

[英]mysql change constraint name, how?

create table Foo(
 userId bigint(20) not null,
 KEY `Foo_userId` (`userId`),
 CONSTRAINT `Foo_userId` FOREIGN KEY (`userId`) REFERENCES `User` (`id`)
);

如何將鍵/約束名稱從Foo_userId更改為Bar_userId,只更改名稱。 我知道他們可以先丟棄,然后重新創建它們。 我正在尋找一種簡單的方式

alter table Foo rename KEY Foo_userId Bar_userId;
alter table Foo rename CONSTRAINT Foo_userId Bar_userId;

在mysql中有這樣的東西嗎? 謝謝。

要更改約束名稱或屬性,可以刪除舊外鍵約束並添加新約束。 這是它真正對我有用的唯一解決方案。

alter table FOO 
drop foreign key Foo_userId,
add constraint Bar_userId foreign key (`userId`) references`User` (`id`)

是另一個幫助我的答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM