简体   繁体   English

使用MYSQL上每个值的条件更新具有相同列名的多个表

[英]UPDATE multiple table with same column name with condition for each value on MYSQL

I've a column "pid" and a lot of table on each database , then I want to update all table from every database with column "pid" and set 'pid' = 5 where 'pid' = 3 and set 'pid' = 6 where 'pid = '7' on 1 query . 我在每个数据库上都有一列“ pid”和很多表,然后我想用“ pid”列更新每个数据库的所有表,并设置“ pid” = 5,其中“ pid” = 3并设置“ pid” = 6,其中1个查询中的'pid ='7'。

I've find post like this and try to apply it: 我发现这样的帖子,然后尝试将其应用:

Select 'UPDATE ' + TABLE_NAME + ' SET pid = ''5'' '
From INFORMATION_SCHEMA.COLUMNS 
WHERE COLUMN_NAME = 'pid'

Without condition for try it , then MYSQL just return me a select with value 0 . 没有条件尝试,则MYSQL仅返回值为0的选择。

'UPDATE ' + TABLE_NAME + ' SET pid = ''5'' '
                                           0

Need a little help and explain for make this query work and understand how its work . 需要一点帮助和说明,以使此查询有效,并了解其工作原理。

Really thanks everyone :) 真的谢谢大家:)

UPDATE table_name
SET pid = 5
WHERE pid = 3;

It should be implemented like this. 应该这样实现。 You simply tell to update the table named table_name to set pid as ' 5 ' wherever it finds it as ' 3 '. 您只要告诉更新名为table_name的表,就可以将pid设置为“ 5 ”,无论它在何处找到“ 3 ”。

Read also here . 在这里阅读。 ;) ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM