yellow-fin
作者yellow-fin·2012-06-25 08:15
项目经理·浙江兰德纵横网络技术有限公司

使用 SQL PL 的 BEFORE INSERT 触发器

字数 593阅读 2265评论 0赞 0

CREATE TRIGGER business_rules
BEFORE INSERT ON empprojact
REFERENCING NEW AS n
FOR EACH ROW
  BEGIN ATOMIC
  -- Business Rule One (Project ending date Can't be NULL)
  IF (n.emendate IS NULL) THEN
     SET n.emendate = CURRENT date;
  END IF;

  -- Business Rule Two (Project ending date Can't end in last month of the year)
  IF (n.emendate BETWEEN '2009-12-01' AND '2009-12-31') THEN
     SIGNAL SQLSTATE '90000'
        SET MESSAGE_TEXT = 'Business Rule violation - 90000';
  END IF;

  END!

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

0

添加新评论0 条评论

Ctrl+Enter 发表

作者其他文章

相关问题

X社区推广