开发者

How to add an autoincrement field for an existing table and populate it with serial numbers for rows?

开发者 https://www.devze.com 2023-01-13 21:35 出处:网络
e.g. I have a table: create table test (testdata varchar2(255)); then I need an autoincrement field: alter table test add id numeric(10);

e.g. I have a table:

create table test (testdata varchar2(255));

then I need an autoincrement field:

alter table test add id numeric(10);

create sequence test_seq 
start with 1 
increment by 1 
nomaxvalue; 

create trigger test_trigger
before insert on test
for each row
begin
select test_seq.nextval into :new.id from dual;
end;

what should I do next to populate already existing fiel开发者_Go百科ds with their serial numbers in "id" ?


update test
set id = test_seq.nextval
0

精彩评论

暂无评论...
验证码 换一张
取 消