Mysql 查询库,表,列信息

本文分享了使用SQL查询数据库表结构和信息的实用技巧,包括查询所有表结构、指定表信息及列详细信息的SQL语句,适合用于代码生成器,帮助开发者高效掌握数据库信息。

好记忆不如烂笔头,能记下点东西,就记下点,有时间拿出来看看,也会发觉不一样的感受.

1.查询当前数据库所有表结构的信息

select
   table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables
where
   table_schema = (select database())
order by
   create_time desc

2.查询指定表的信息

select
   table_name tableName, engine, table_comment tableComment, create_time createTime
from
   information_schema.tables
where
   table_schema = (select database()) and table_name = 'test'

3.查询指定表的列的信息

select
   table_name as tableName, column_name as  columnName,ordinal_position as ordinalPosition,column_default as columnDefault,is_nullable    as isNullable, data_type as dataType,character_maximum_length as characterMaximumLength,numeric_precision as numericPrecision, column_comment as columnComment, column_key as columnKey, extra
from
   information_schema.columns
where
   table_name = 'test' and table_schema = (select database()) order by ordinal_position

这些sql的作用,主要用来做代码生成器所用,列的其他信息,可以参见:

https://blog.youkuaiyun.com/qq_40803316/article/details/84656511

不同的数据库,对于查询有不同的sql语句。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值