下面为大家介绍利用SQL查询语句获取Mysql数据库中表的表名,表描述、字段ID、字段名、数据类型、长度、精度、是否可以为null、默认值、是否自增、是否是主键、列描述
一、查询表信息(表名/表描述)
1
2
|
SELECT table_name name ,TABLE_COMMENT value FROM INFORMATION_SCHEMA.TABLES WHERE table_type= 'base table' and table_schema = '数据库名' order by table_name asc |
二、查询字段信息(字段ID/字段名/数据类型/长度/精度/是否可以为null/默认值/是否自增/是否是主键/列描述)
方法一:
SHOW FULL COLUMNS FROM 表名
方法二:
1
2
3
4
5
|
select ORDINAL_POSITION as Colorder,Column_Name as ColumnName,data_type as TypeName,COLUMN_COMMENT as DeText, ( case when data_type = 'float' or data_type = 'double' or data_type = 'decimal' then NUMERIC_PRECISION else CHARACTER_MAXIMUM_LENGTH end ) as length, NUMERIC_SCALE as Scale,( case when EXTRA= 'auto_increment' then 1 else 0 end ) as IsIdentity,( case when COLUMN_KEY= 'PRI' then 1 else 0 end ) as IsPK, ( case when IS_NULLABLE = 'NO' then 0 else 1 end ) as CanNull,COLUMN_DEFAULT as DefaultVal from information_schema.columns where table_schema = '数据库名' and table_name = '表名' order by ORDINAL_POSITION asc |
以上即是Sql获取MySql数据库中的表名和描述表中字段名数据类型等列信息的几种方法,如果不是你所需要的,还可以看下下面的相关文章
原文链接:http://www.cnblogs.com/lztkdr/p/7839952.html