Question

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;

But I keep getting this error:

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

What am I doing wrong?

Was it helpful?

Solution

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

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top