Wednesday, February 25, 2009

Autoincrement

As some of you may know, Firebird does not offer autoincrement like MySQL. For Firebird you must use generators, which is Firebird-speak for sequences. I'll post some code later. Or if anyone else has some code to post, feel free.

5 comments:

Yawo said...

I need that. I've been struggling with that for a while

Clay Smith said...

<3 MySQL :)

Unknown said...

Here's a useful link:
http://www.firebirdsql.org/manual/generatorguide-sqlsyntax.html

Here's another one:
http://www.firebirdsql.org/manual/generatorguide-basics.html

Yawo said...

Link to the auto-incrementing

http://firebirdsql.org/dotnetfirebird/blog/2005/01/migration-from-mysql-i.html

Unknown said...

Here is code that creates an auto-incrementer for a table called MENUITEM. By default the counter will start at 1.

CREATE SEQUENCE create_item_id;

SET TERM !;
CREATE TRIGGER set_item_id FOR MENUITEM
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
new.ID = gen_id(create_item_id, 1);
END!
SET TERM;!