I want to add a column to an existing Firebird database (version 2.5) and write a procedure by which I can assign each record a different value. Something like add a column and autogenerate the data for it.
Like, if I add a new column called “ID” (number) I want then initialize a unique value to each of the records. So, my ID column will have records from say 1 to 500. How can I achieve this by using only sql script (i.e. without using some high-level programming language for generating sql commands)?
Basically what I need is something like identity columns in Firebird 3.0:
alter table MY_TABLE
add ID int identity(1,1)
This columns will have a default value of 1:
You can have an auto-incrementing PK using a generator and a BEFORE INSERT trigger:
I didn’t understand when you need the random data you said, though.
note that they are two different examples, they are not to be used on together on the same column