最初,运行时我们可以看到以下内容SELECT * FROM block_custom;
:
+-----+------------------+--------+-----------+
| bid | body | info | format |
+-----+------------------+--------+-----------+
| 1 | Block1 body here | Block1 | full_html |
| 2 | Block2 body here | Block2 | full_html |
| 3 | Block3 body here | Block3 | full_html |
+-----+------------------+--------+-----------+
为了替换表的info
和,我使用以下查询:body
block_custom
update block_custom set info = replace(info,'Block2','Block2new');
update block_custom set body = replace(body,'body here','newbody here');
这是我的查询的解释:
update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
当运行此查询进行更改时body
,它将替换所有行和列body
。
如何使其仅在第 2 行发生变化(bid 2
)?
答案1
一如既往,用条款来限制它WHERE
。
... WHERE bid=2