1. 要查询数据库 “mammothcode” 下所有表名以及表注释
/* 查询数据库 ‘mammothcode’ 所有表注释 */ SELECT TABLE_NAME,TABLE_COMMENT FROM information_schema.TABLES WHERE table_schema='mammothcode';
2. 要查询表字段的注释
/* 查询数据库 ‘mammothcode’ 下表 ‘t_adminuser’ 所有字段注释 */ SELECT COLUMN_NAME,column_comment FROM INFORMATION_SCHEMA.Columns WHERE table_name='t_adminuser' AND table_schema='mammothcode'
3. 一次性查询数据库 “mammothcode” 下表注释以及对应表字段注释
SELECT t.TABLE_NAME,t.TABLE_COMMENT,c.COLUMN_NAME,c.COLUMN_TYPE,c.COLUMN_COMMENT FROM information_schema.TABLES t,INFORMATION_SCHEMA.Columns c WHERE c.TABLE_NAME=t.TABLE_NAME AND t.`TABLE_SCHEMA`='mammothcode'
4. 一次性查询数据库 “mammothcode” 下所有包含userid的表注释以及对应表字段注释
SELECT tab.TABLE_NAME,tab.TABLE_COMMENT FROM information_schema.COLUMNS col LEFT JOIN information_schema.`TABLES` tab on col.TABLE_NAME = tab.TABLE_NAME and col.table_schema = tab.table_schema WHERE col.COLUMN_NAME='userid' and col.table_schema = 'mammothcode'