小编Ale*_*der的帖子

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万
查看次数

标签 统计

mysql ×1