Mysql 查询库,表,列信息

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

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语句。

猜你喜欢

转载自blog.csdn.net/supingemail/article/details/106042566