phpMyAdmin触发gui检查年龄 [英] phpMyAdmin trigger gui checking age

查看:98
本文介绍了phpMyAdmin触发gui检查年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查年龄是否大于18岁,然后再将记录插入员工"表.我正在使用phpMyAdmin gui触发工具.但是,当我在定义"部分中键入此脚本时,会出现以下错误.

I want to check whether age is greater than 18 years before inserting the record to 'employees' table. I'm using phpMyAdmin gui trigger tool. But it gives following error when I type this script in Definition section.

BEGIN
    IF (DATEDIFF(CURRENT_DATE(),NEW.birth_date) < 6570) THEN
        RAISEERROR('Age is less than 18 years!',16,1)
        ROLLBACK
    END IF
END

请帮助我解决这个问题.

Please help me to resolve this.

推荐答案

RAISEERRORROLLBACK在TSQL(Microsoft SQL Server)语法中使用.

RAISEERROR and ROLLBACK are used in TSQL (Microsoft SQL Server) syntax.

对于MySQL,我们使用 SIGNAL .. SET MESSAGE_TEXT .. 在触发器内引发异常:

In the case of MySQL, we use SIGNAL .. SET MESSAGE_TEXT .. to throw an exception inside the Trigger:

BEGIN
    IF (DATEDIFF(CURRENT_DATE(),NEW.birth_date) < 6570) THEN

      -- Throw Exception
      SIGNAL SQLSTATE '45000' 
        SET MESSAGE_TEXT = 'Age is less than 18 years!';

    END IF;  -- A semicolon (delimiter) is missing here
END

要发出通用SQLSTATE值的信号,请使用"45000",这表示 未处理的用户定义异常."

To signal a generic SQLSTATE value, use '45000', which means "unhandled user-defined exception."

执行SIGNAL后可访问的错误值是 由SIGNAL语句和MESSAGE_TEXT引发的SQLSTATE值和 MYSQL_ERRNO项目.

The error values that are accessible after SIGNAL executes are the SQLSTATE value raised by the SIGNAL statement and the MESSAGE_TEXT and MYSQL_ERRNO items.

这篇关于phpMyAdmin触发gui检查年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆