mysql 查詢表字段名,注釋 , 以及sql拼接查詢出的內容


#sql查詢字段名,注釋操作拼接

#查詢字段名和注釋  
select COLUMN_NAME,COLUMN_COMMENT from information_schema.COLUMNS where table_name = '表名' and table_schema = '庫名' order by ordinal_position 
#查詢整個內容
select * from information_schema.COLUMNS where table_name = '表名' and table_schema = '庫名' order by ordinal_position 


#拼接  group_concat(field,SEPARATOR '拼接字符')  
select group_concat(COLUMN_NAME SEPARATOR ';'),group_concat(COLUMN_COMMENT SEPARATOR ';') from information_schema.COLUMNS where table_name = '表名' and table_schema = '庫名' order by ordinal_position 

#按順序排字段拼接 group_concat(field order by field,SEPARATOR '字符')
select group_concat(COLUMN_NAME order by ordinal_position SEPARATOR ';'),group_concat(COLUMN_COMMENT ORDER BY ordinal_position SEPARATOR ';') from information_schema.COLUMNS where table_name = '表名' and table_schema = '庫名' order by ordinal_position 

#整個庫下的所有表
select TABLE_NAME,group_concat(COLUMN_NAME order by ordinal_position SEPARATOR ';'),group_concat(COLUMN_COMMENT ORDER BY ordinal_position SEPARATOR ';') from information_schema.COLUMNS where table_schema = '庫名'  GROUP BY TABLE_NAME


#整個服務器下的所有庫中表,每個表的字段和注釋的拼接
select TABLE_SCHEMA,TABLE_NAME,group_concat(COLUMN_NAME order by ordinal_position SEPARATOR ';'),group_concat(COLUMN_COMMENT ORDER BY ordinal_position SEPARATOR ';') from information_schema.COLUMNS   GROUP BY TABLE_NAME,TABLE_SCHEMA ORDER BY TABLE_SCHEMA


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM