好记忆不如烂笔头,能记下点东西,就记下点,有时间拿出来看看,也会发觉不一样的感受.
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语句。
本文分享了使用SQL查询数据库表结构和信息的实用技巧,包括查询所有表结构、指定表信息及列详细信息的SQL语句,适合用于代码生成器,帮助开发者高效掌握数据库信息。
1190

被折叠的 条评论
为什么被折叠?



