Is there an easy way to create auto increment field using Firebird? I have installed the FlameRobin admin tool, but the process of creating an auto increment field through the tool is complex. Can I not create such an identity field just by clicking a checkbox or using some other tool other than Flamerobin?
相关问题
- C# how to invoke a field initializer using reflect
- MySQL: Why does my INSERT statement skip 56 number
- Firebird 2.5 exception handling within autonomous
- Private field accessible from another instance of
- Dynamic Form fields in `__init__` in Django admin
相关文章
- Max Size of SQL Server Auto-Identity Field
- how to set H2 primary key id to auto_increment?
- Factor Clojure code setting many different fields
- Getting number of fields in a database with an SQL
- (1054)Unknown column in 'field list' - Mys
- How add a function in openERP 7?
- Django/Python: How can I make the following number
- How to count number of fields in a table?
Firebird 2.5 and earlier do not have auto-increment fields. You need to create them yourself with a sequence (aka generator) and a trigger.
Sequence is the SQL standard term and generator is the historical Firebird term, they are both used.
To create a sequence:
To create a trigger to always generate the id on a table
T1
with primary keyID
:See also: How to create an autoincrement column?
Firebird 3 makes this a little bit easier, as it introduces identity columns. In practice it is syntactic sugar for generating a sequence + trigger for you.
For example
Firebird 3 only supports "
generated by default
", which means users are able to specify their own id values (which might lead to duplicate value errors); "generated always
" will be added Firebird 4.See also the Firebird 3 release notes, section "Identity Column Type".
Flamerobin also provides tooling to create a sequence + trigger for you. If you have an existing table, you can follow these steps:
Open the table properties:
Open the column properties of the primary key column
Default column properties, select new generator and create trigger:
Generator (sequence) and trigger code generated by flamerobin. Note that contrary to my example above this trigger allows a user to specify their own id value, with some logic to avoid future duplicates. Execute this (and don't forget to commit):