使用RAISE创建触发器 [英] Create triggers with RAISE

查看:141
本文介绍了使用RAISE创建触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图将一张表限制为仅一条记录,并禁止所有尝试添加更多记录的尝试。
我创建了此触发器:在my_tbl上插入之前创建触发器abort_insert_to_my_tbl
开始
RAISE(ABORT,您不能将记录添加到my_tbl)
END;

I'm trying to limit a table to only one record and disable all attempt to add more. I have created this trigger: CREATE TRIGGER abort_insert_to_my_tbl BEFORE INSERT ON my_tbl BEGIN RAISE(ABORT,"You can't add records to my_tbl") END;

但我一直收到此错误:

Error: near line 3080: near "RAISE": syntax error  

什么是我做错了吗?

推荐答案

作为文档显示,RAISE是函数,而不是语句,因此不能直接在触发器主体中使用。

As the documentation shows, RAISE is a function, not a statement, so it cannot be used directly in the trigger body.

要在触发器主体中使用函数语句,例如使用SELECT语句:

To use a function in a statement, use, for example, a SELECT statement:

CREATE TRIGGER abort_insert_to_my_tbl
BEFORE INSERT ON my_tbl
BEGIN
    SELECT RAISE(ABORT, 'You can''t add records to my_tbl');
END;

这篇关于使用RAISE创建触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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