私は非常に単純な質問をしているので、誰かが助けてくれることを願っています.
ID と CREDIT を持つ MySQL テーブルがあります。クレジットが0の場合に更新値を変更する更新トリガーを実行したいので、「if old.CREDIT = 0 then new.CREDIT = 0.001」のようなものです。では、トリガーの構文はどうなるでしょうか。ありがとう。
単純な例から複雑な例を示すMySQLトリガーのチュートリアルをお読みください。
これがトリガーの簡単な例before update
です。これはあなたを助けるかもしれません。
テーブル名を。と仮定しますcredit_info
。
delimiter //
create trigger sample_trigger_before_update_on_credit_info before update on test.credit_info
for each row begin
if new.credit = 0 then
set new.credit = 0.001;
end if;
end;
//
delimiter ;
たとえば、テーブルには次の2つのレコードがあります。
+------+--------+
| id | credit |
+------+--------+
| 1 | 1.000 |
| 2 | 3.000 |
+------+--------+
次のように更新ステートメントを発行する場合:
update credit_info set credit=0 where id=2;
結果のレコードは次のようになります。
+------+--------+
| id | credit |
+------+--------+
| 2 | 0.001 |
+------+--------+
サンプルの例があなたのエネルギーを加速することを願っています。