1、/* 查詢數據庫 test 所有表注釋 */
SELECT TABLE_NAME,TABLE_COMMENT FROM information_schema.TABLES WHERE table_schema='test';
2、要查詢表字段的注釋
SELECT COLUMN_NAME,column_comment FROM INFORMATION_SCHEMA.Columns WHERE table_name='class' AND table_schema='test';
3、一次性查詢數據庫 "test" 下表注釋以及對應表字段注釋
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`='test';
4、項目中使用的,查詢數據庫所有表的相關字段,屬性
SELECT 'xx系統' system_name, table_comment table_comment, a.table_name, column_comment, column_name, CASE WHEN column_key ='PRI' THEN 'Y' ELSE 'N' END is_key, CASE WHEN column_name='id' OR column_name='created_by' THEN '自動' ELSE '手動' END get_type, column_type FROM (SELECT * FROM information_schema.COLUMNS WHERE table_schema ='test')a LEFT JOIN (SELECT table_name,table_comment FROM information_schema.TABLES WHERE table_schema='test') b ON a.table_name = b.table_name ORDER BY table_name,ordinal_position ;