MySQL:如何查看表上的所有约束?

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

并添加了一个约束

alter table t2
add constraint c2 check (b<20);

然后我尝试查看所有(四个)约束

show table status
from tenn #-->the name of my database
like 't2';

然后

show create table t2;

然后

select *
from information_schema.key_column_usage
where table_name='t2';

最后

select *
from information_schema.table_constraints
where table_name='t2';

但这些都没有显示所有四个约束。谁能告诉我如何查看所有这些?

非常感谢!

最佳答案

select COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_COLUMN_NAME, REFERENCED_TABLE_NAME
from information_schema.KEY_COLUMN_USAGE
where TABLE_NAME = 'table to be checked';

关于MySQL:如何查看表上的所有约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5094948/

相关文章:

php - Android PHP和mysql的最佳教程

mysql - 如何筛选结果

php - 将数据添加到json中

php - 为类建立 PDO 连接的正确方法

php - 数据库信息到Facebook Page Tab? XML 和 curl

mysql每月中值

mysql - Perl 在脚本之间传递数据而不使用查询字符串

php - 查询 : Find string in database field

mysql - 将 MySQL *.sql 脚本(语句)转换为 MS SQL SERVER *.sql 脚本(语句)

mysql - mysql innodb 表中的 count(*) 导致数据通过 spring xd 泵送时结果不一致