Subject Re: [firebird-support] Add and populate a primary key
Author Martijn Tonies
Hello Marc,

> I have imported data from an old database, with no primary keys in
> most tables. I want to add and populate a primary key to them, but I
> don't know how to do it.
>
> I remember there is some kind of virtual column to identify a row in a
> table with no primary key, but I don't remember his name and I can't
> find it.

RDB$DB_KEY, but it cannot be used as a primary key in normal
usuage.

> How can I do something like that (what is then name of XXX field name) ? :
>
> -----
>
> alter table OLD_DATA add ID integer;

create generator old_data_generator;

update old_data set id = gen_id(old_data_generator, 1);

> ----
>
> alter table OLD_DATA add constraint PK_OLD_DATA primary key (ID)
>
> ---

Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle &
MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com