How to make a trigger for an autoincrement field without using a generator

Sometimes we need to make an autoincrement field (as in the primary key of a table) but we know that such table won’t have a concurrent use, so we don’t want to use a generator to get the values.

For such situations i use this trigger, obviously, it must be a BEFORE INSERT one:

 CREATE TRIGGER DATOS_BI FOR DATOS
ACTIVE BEFORE INSERT
AS
BEGIN
SELECT COALESCE(MAX(ID),0) + 1 FROM DATOS INTO NEW.ID;
END

Where ID is the primary key field and DATOS is the name of the table.

The COALESCE function is for the case when there are not rows in the table, and the MAX function returns NULL, so COALESCE returns 0 in that case.