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

#拼接数据库名和表名
select CONCAT(TABLE_SCHEMA,'.',TABLE_NAME) from information_schema.COLUMNS   GROUP BY TABLE_NAME,TABLE_SCHEMA ORDER BY TABLE_SCHEMA;
 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值