Hi Sam Carleton wrote:
> This is my first BEFORE INSERT trigger in SQLite and I am getting an
> error:
>
> SQL error: near "new": syntax error
> CREATE TRIGGER ti_Customer BEFORE INSERT ON Customer
> BEGIN
> new.instertedon = DATETIME('NOW');
> new.updatedon = new.instertedon;
> new.updatedby = new.insertedby;
> END;
I think you simply want this instead, which is correct syntax, and
uses AFTER instead of BEFORE, since you can't update a row that isn't
there yet:
CREATE TRIGGER ti_Customer AFTER INSERT ON Customer
BEGIN
UPDATE Customer
SET instertedon = DATETIME('NOW')
, updatedon = DATETIME('NOW')
, updatedby = new.insertedby
WHERE CustomerId = new.CustomerId
;
END;
Tom
BareFeet
--
Comparison of SQLite GUI applications:
http://www.tandb.com.au/sqlite/compare/?ml
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users