我有一个包含多个列的mysql表: id,starttime(timestamp),endtime(timestamp),status。
我想将触发器添加到:
mysql中的新手,我很难宣布这些触发器......
感谢您的帮助,
答案 0 :(得分:0)
以下是完整的解决方案: (用于drupal)
触发器1:
$slqquery = 'CREATE TRIGGER `trigger_name` ';
$slqquery .= 'BEFORE INSERT ON `table_name` ';
$slqquery .= 'FOR EACH ROW BEGIN SET NEW.starttime=NOW(); END;';
$query = db_query($slqquery);
触发器2:
$slqquery = 'CREATE TRIGGER `trigger_name` ';
$slqquery .= 'BEFORE UPDATE ON `table_name` ';
$slqquery .= 'FOR EACH ROW BEGIN ';
$slqquery .= "IF (!(OLD.column_name <=> NEW.column_name) AND (NEW.column_name <=> 'WHATEVER')) THEN ";
$slqquery .= 'SET NEW.endtime=NOW(); ';
$slqquery .= 'END IF; END;';
$query = db_query($slqquery);
如果可以提供帮助。