前言
写更新语句的时候,希望能保留回滚的能力,可以尝试使用 concat 语句。先拷贝出回滚语句,再执行脚本。
需求
- 已知person表
- 为所有名称增加test字段
concat 实现
SELECT
id,
NAME,
concat( "update person set name = 'test_", NAME, "' where id = ", id, ";" ) AS script,
concat( "update person set name = '", NAME, "' where id = ", id, ";" ) AS rollback_script
FROM
person;
- 执行script 前拷贝rollback_script
Excel 实现
- excel 的功能会更强大点,可以自定义更新值
- script 公式 (&是连接符)
="update person set name = '"&B2&"' where id ="&A2&";"
- rollback script 公式
="update person set name = '"&B2&"' where id ="&A2&";"