Mysql 当使用触发器更改另一个字段时,更改表中字段的值

Mysql 当使用触发器更改另一个字段时,更改表中字段的值,mysql,sql,datetime,triggers,sql-update,Mysql,Sql,Datetime,Triggers,Sql Update,大家早上好。 我在mysql中有这样一个表: CREATE TABLE NC ( ID INTEGER AUTO_INCREMENT NOT null, reportingDate DATE, closingDate DATE, State VARCHAR(20), PRIMARY KEY(CodNC) ) 我需要的是自动更改字段“ClosingDate”的值,直到今天,每次使用触发器将字段“State”的值更改为

大家早上好。 我在mysql中有这样一个表:

CREATE TABLE NC
(
        ID INTEGER AUTO_INCREMENT NOT null,
        reportingDate DATE,
        closingDate DATE,
        State VARCHAR(20),
        PRIMARY KEY(CodNC)
)
我需要的是自动更改字段“ClosingDate”的值,直到今天,每次使用触发器将字段“State”的值更改为“Closed”。
谢谢

这看起来像是更新前的一个简单的
触发器:

delimiter //

create trigger trg_nc_before_state_update
before update on nc
for each row
begin
    if new.state = 'Closed' and not old.state <=> 'Closed' then
        set new.closingdate = current_date;
    end if;
end
//

delimiter ;
分隔符//
在状态更新之前创建触发器trg\u nc\u
更新nc之前
每行
开始
如果new.state='Closed'而不是old.state'Closed',则
设置new.closingdate=当前\日期;
如果结束;
结束
//
定界符;

它可以工作!!!谢谢你来@Miky打赌。如果我的答案正确回答了你的问题,那么点击复选标记。。。谢谢