相关疑难解决方法(0)

MySQL删除一些外键

我有一个表,其主键在其他几个表中使用,并有几个外键到其他表.

CREATE TABLE location (
   locationID INT NOT NULL AUTO_INCREMENT PRIMARY KEY
   ...
) ENGINE = InnoDB;

CREATE TABLE assignment (
   assignmentID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
   locationID INT NOT NULL,
   FOREIGN KEY locationIDX (locationID) REFERENCES location (locationID)
   ...
) ENGINE = InnoDB;

CREATE TABLE assignmentStuff (
   ...
   assignmentID INT NOT NULL,
   FOREIGN KEY assignmentIDX (assignmentID) REFERENCES assignment (assignmentID)
) ENGINE = InnoDB;
Run Code Online (Sandbox Code Playgroud)

问题是,当我试图删除其中一个外键列(即locationIDX)时,它会给我一个错误.

"ERROR 1025(HY000):重命名时出错"

如何在不发生此错误的情况下删除上面的分配表中的列?

mysql constraints foreign-keys mysql-error-1025

176
推荐指数
5
解决办法
32万
查看次数

MySQL:如何在表上看到所有约束?

我正在学习SQL以及困扰我的是,我似乎无法在桌面上找到所有约束.我创建了表

create table t2
(a integer not null primary key,
b integer not null, constraint c1 check(b>0),
constraint fk1 foreign key(a) references t1(a));
Run Code Online (Sandbox Code Playgroud)

并添加了一个约束

alter table t2
add constraint c2 check (b<20);
Run Code Online (Sandbox Code Playgroud)

然后我试着看到所有(四个)约束

show table status
from tenn #-->the name of my database
like 't2';
Run Code Online (Sandbox Code Playgroud)

然后

show create table t2;
Run Code Online (Sandbox Code Playgroud)

然后

select *
from information_schema.key_column_usage
where table_name='t2';
Run Code Online (Sandbox Code Playgroud)

最后

select *
from information_schema.table_constraints
where table_name='t2';
Run Code Online (Sandbox Code Playgroud)

但这些都没有显示出所有四个约束.谁能告诉我怎么看他们所有人?

非常感谢!

mysql

42
推荐指数
6
解决办法
7万
查看次数