[英]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.