SELECT
COLUMN_NAME 列名,
COLUMN_TYPE 数据类型,
DATA_TYPE 字段类型,
CHARACTER_MAXIMUM_LENGTH 长度,
IS_NULLABLE 是否为空,
COLUMN_DEFAULT 默认值,
COLUMN_COMMENT 备注
FROM
INFORMATION_SCHEMA.COLUMNS
where
-- dbname为数据库名称,到时候只需要修改成你要导出表结构的数据库即可
table_schema ='tkcxmessagedev'
AND
-- article为表名,到时候换成你要导出的表的名称
-- 如果不写的话,默认会查询出所有表中的数据,这样可能就分不清到底哪些字段是哪张表中的了,所以还是建议写上要导出的名名称
table_name = 'cx_auth_function'
查询数据库中所有表名
select table_name from information_schema.tables where table_schema='csdb' and table_type='base table';
查询指定数据库中指定表的所有字段名column_name
select column_name from information_schema.columns where table_schema='csdb' and table_name='users'
《查询所有的包含 sys_type 字段的表》
select TABLE_NAME,column_name from information_schema.columns where table_schema='tkcxmessagedev' and column_name='sys_type'
查询所有的主外键的关系
select CONSTRAINT_NAME, TABLE_NAME,COLUMN_NAME,REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME from INFORMATION_SCHEMA.KEY_COLUMN_USAGE t where t.TABLE_SCHEMA = 'tkcxmessage' ;
查询一个表的所有的索引的信息(消息平台为例)
select TABLE_NAME,INDEX_NAME,COLUMN_NAME,INDEX_TYPE
from INFORMATION_SCHEMA.STATISTICS where TABLE_SCHEMA='tkcxmessage' AND TABLE_NAME NOT IN ('cx_company','cx_treedic','cx_festival') ;