背景
有一个商品的名称配置错误了,需要进行修改,但是涉及到的表太多了,因为商品的sku_name被冗余到了很多表中,一个一个的找非常的费事费力,特地记下便捷查询操作以备后用。
数据库SQL快捷查询
1.查询包含某个字段的所有表名
SELECT DISTINCT table_name FROM information_schema.columns WHERE table_schema = 'db_lingyejun' and column_name='sku_id';
2.查询同时含有两个字段的所有表名
SELECT DISTINCT a.table_name FROM information_schema.columns a, information_schema.columns b WHERE a.table_name = b.table_name and a.table_schema = 'db_lingyejun' and a.column_name='sku_id' and b.table_schema = 'db_lingyejun' and b.column_name='sku_name';
3.拼接SQL动态生成针对此字段的所有更新语句
SELECT CONCAT('UPDATE ', a.table_name, 'set sku_name = "IPHONE 13PRO" where sku_id = 1106;') FROM information_schema.columns a, information_schema.columns b WHERE a.table_name = b.table_name and a.table_schema = 'db_lingyejun' and a.column_name='sku_id' and b.table_schema = 'db_lingyejun' and b.column_name='sku_name';
本篇文章如有帮助到您,请给「翎野君」点个赞,感谢您的支持。
首发链接:https://www.cnblogs.com/lingyejun/p/16934219.html
标签:sku,information,name,Mysql,表名,lingyejun,查询数据库,table,schema From: https://www.cnblogs.com/lingyejun/p/16934219.html