此时情绪此时天,无事小神仙
好好生活,平平淡淡每一天

编辑

Mysql 查询数据库万能SQL

查询数据库表

image

SELECT concat(TABLE_SCHEMA,".",TABLE_NAME) as tableName,TABLE_COMMENT,ENGINE,TABLE_ROWS
FROM information_schema.TABLES where 1=1 
and TABLE_SCHEMA  = 'userdb'
and TABLE_NAME like '%user%'
and TABLE_COMMENT like '%用户%'
limit 30;

查询数据库表字段

image

-- 查询数据库表字段
select tab.TABLE_SCHEMA,tab.TABLE_NAME,tab.TABLE_COMMENT,col.COLUMN_NAME,col.COLUMN_COMMENT,
	col.COLUMN_TYPE,col.IS_NULLABLE as 'IS_NULLABLE(是否可为空)',col.COLUMN_DEFAULT,col.COLUMN_KEY
FROM information_schema.`COLUMNS` col 
LEFT JOIN information_schema.`TABLES` tab on tab.TABLE_SCHEMA = col.TABLE_SCHEMA and tab.TABLE_NAME = col.TABLE_NAME 
where 1 = 1 
and col.TABLE_SCHEMA = 'userdb' 
and col.TABLE_NAME like '%user%' 
and col.COLUMN_NAME like '%name%'
and col.COLUMN_COMMENT like '%用户名%'
order by col.TABLE_SCHEMA,col.TABLE_NAME
limit 30;

查询数据库表索引字段

image

select DISTINCT col.TABLE_SCHEMA,col.TABLE_NAME,col.COLUMN_NAME,col.COLUMN_COMMENT,IF(sta.INDEX_NAME = 'PRIMARY','YES','') 是否为主键索引,IF(sta.INDEX_NAME != 'PRIMARY','YES','') 是否为索引
FROM information_schema.`COLUMNS` col 
INNER JOIN information_schema.STATISTICS sta on sta.TABLE_SCHEMA = col.TABLE_SCHEMA and sta.TABLE_NAME = col.TABLE_NAME and sta.COLUMN_NAME = col.COLUMN_NAME 
where 1 = 1 
and col.TABLE_SCHEMA = 'userdb' 
and col.TABLE_NAME like '%user%' 
-- and col.COLUMN_NAME like '%name%'
-- and col.COLUMN_COMMENT like '%用户名%'
order by col.TABLE_SCHEMA,col.TABLE_NAME 
limit 30
posted @ 2019-11-20 14:55  踏步  阅读(114)  评论(0编辑  收藏  举报