mysql 如何查看constraint定义的的所有约束,MySQL:如何查看表上的所有约束?

I'm learning SQL and what bothers me, is that I seem unable to find ALL constraints on a table. I created the table with

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));

and added a constraint with

alter table t2

add constraint c2 check (b<20);

I then tried to see ALL (four) constraints with

show table status

from tenn #-->the name of my database

like 't2';

and then

show create table t2;

and then

select *

from information_schema.key_column_usage

where table_name='t2';

and finally

select *

from information_schema.table_constraints

where table_name='t2';

But none of these shows all four constraints. Could anyone tell me how to see all of them?

Thanks a lot!

解决方案select COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_COLUMN_NAME, REFERENCED_TABLE_NAME

from information_schema.KEY_COLUMN_USAGE

where TABLE_NAME = 'table to be checked';

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值