-1

我正在尝试更新 contractnum 的值,当将某些内容插入 table1 时该值应该为空。我想将其更新为 field2 始终是唯一编号的任何内容。

DELIMITER //
CREATE TRIGGER database1.Update_Contract_Num
BEFORE INSERT ON database1.table1
FOR EACH ROW
BEGIN
/*Update contract Num when new doc gets inserted and copy the contents of field1*/
IF contractnum IS NULL THEN
SET CONTRACTNUM = field2
END IF
END//
DELIMITER ;
4

1 回答 1

0

你有几个语法问题:

  1. 您需要使用NEW前缀来引用要插入的行的列值
  2. 您需要用分号终止某些行

这应该更接近您的需要:

DELIMITER //
CREATE TRIGGER database1.Update_Contract_Num
BEFORE INSERT ON database1.table1
FOR EACH ROW
BEGIN
  /*Update contract Num when new doc gets inserted and copy the contents of field1*/
  IF NEW.contractnum IS NULL THEN
    SET NEW.CONTRACTNUM = NEW.field2;
  END IF;
END //
DELIMITER ;
于 2013-02-27T19:37:12.073 回答