MySQL 查询某个数据库中的所有表名、某个表的字段名、字段类型、字段注释

有时我们需要对数据进行探究,首先想到的就是该表有哪些字段,以及字段类型、注释,那么我们该如何快速的知道呢?

可参考下列的

1、查询 Test 数据库中有哪些表,查询结果如下: 

2、查询 Test 数据库中 test_01 表的字段名、字段类型、字段类型 + 长度,查询结果如下:

3、查询 Test 数据库中 test_01 表的字段名、注释,查询结果如下:

SQL 汇集:

字段说明:

information_schema.tables 
表名      :table_name
字段列名:column_name
字段注释:column_comment
字段类型:data_type
字段类型 + 长度    :column_type

-- 创建 test_01 表
create table Test.test_01(tID int,name varchar(10) COMMENT '名字',sex varchar(10) COMMENT '性别');

-- 1、查询Test数据库有哪些表
select table_name from information_schema.tables where table_schema='Test';

-- 2、查询 Test 数据库中 test_01 表的字段名、字段类型、字段类型 + 长度
select column_name,data_type,column_type
from information_schema.columns
where table_schema = 'Test' and table_name = 'test_01';

-- 3、查询 Test 数据库中 test_01 表的字段名、注释
select column_name,column_comment from information_schema.columns
where table_schema = 'Test' and table_name = 'test_01';

 

希望对你有帮助!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值