• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

Mysql 查询库,表,列信息

Mysql supingemail 2917次浏览 0个评论

.

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.csdn.net/qq_40803316/article/details/84656511

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

 


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明Mysql 查询库,表,列信息
喜欢 (0)

您必须 登录 才能发表评论!

加载中……