下面為大家介紹利用SQL查詢語句獲取Mysql數(shù)據(jù)庫中表的表名,表描述、字段ID、字段名、數(shù)據(jù)類型、長度、精度、是否可以為null、默認值、是否自增、是否是主鍵、列描述
一、查詢表信息(表名/表描述)
SELECT table_name name,TABLE_COMMENT value FROM INFORMATION_SCHEMA.TABLES WHERE table_type='base table'
and table_schema = '數(shù)據(jù)庫名' order by table_name asc
二、查詢字段信息(字段ID/字段名/數(shù)據(jù)類型/長度/精度/是否可以為null/默認值/是否自增/是否是主鍵/列描述)
方法一:
SHOW FULL COLUMNS FROM 表名
方法二:
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 = '數(shù)據(jù)庫名' and table_name = '表名' order by ORDINAL_POSITION asc
以上即是Sql獲取MySql數(shù)據(jù)庫中的表名和描述表中字段名數(shù)據(jù)類型等列信息的幾種方法,如果不是你所需要的,還可以看下下面的相關文章
您可能感興趣的文章:- 使用SQL語句查詢MySQL,SQLServer,Oracle所有數(shù)據(jù)庫名和表名,字段名
- mysql表名忽略大小寫配置方法詳解
- MYSQL將表名稱修改成大寫的存儲過程
- 如何將MySQL的兩個表名對調(diào)
- MySQL 使用SQL語句修改表名的實現(xiàn)