Updating table with autoincrement value

279 views
Skip to first unread message

Ertan Küçükoglu

unread,
Apr 24, 2021, 11:14:33 AM4/24/21
to firebird...@googlegroups.com
Hello,

I am using FirebirdSQL 2.5.9.latest on Windows.

There is that table without any primary key. I want to add an auto increment column using sequence and trigger. Problem I could not figure is filling the new column with incremental numbers starting from 1.

Is it possible to do this without using another table to copy data from here to there and back?

Thanks & Regards,
Ertan Küçükoğlu

Dimitry Sibiryakov

unread,
Apr 24, 2021, 11:22:00 AM4/24/21
to firebird...@googlegroups.com
24.04.2021 17:14, Ertan Küçükoglu wrote:
> Is it possible to do this without using another table to copy data from here to there and
> back?

Something like that:

create generator new_generator;
alter table t add new_id integer not null;
commit;
update t set new_id = gen_id(new_generator, 1);
commit;
alter table t add primary key(new_id);

--
WBR, SD.

Ertan Küçükoglu

unread,
Apr 24, 2021, 2:49:08 PM4/24/21
to firebird...@googlegroups.com
I really appreciated it.

Thank you.

Dimitry Sibiryakov <s...@ibphoenix.com>, 24 Nis 2021 Cmt, 18:22 tarihinde şunu yazdı:
--
You received this message because you are subscribed to the Google Groups "firebird-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-suppo...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/firebird-support/9b2f5fb6-179e-a75e-113c-1894bd238faa%40ibphoenix.com.
Reply all
Reply to author
Forward
0 new messages