dbTalk Databases Forums  

How to fill empty column with number sequence?

comp.database.oracle comp.database.oracle


Discuss How to fill empty column with number sequence? in the comp.database.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ken1
 
Posts: n/a

Default How to fill empty column with number sequence? - 02-13-2004 , 02:45 AM






I am going to drop a primary key from one column and create a new
column to be used as primary key in an existing database.
The old column was a date column which someone earlier though was a
good candidate for a primary key which we all know it's not.

Now I want to add a new field, i.e. called ID, with a normal number
sequence as primary key.

I have dropped the primary key, created the new column, created the
new sequence and created a trigger to generate the primary key for new
inserts.

But I don't know how to generate/update the new ID column with
sequence numbers for the already existing records.

Any ideas?

/Kenneth

Reply With Quote
  #2  
Old   
Ron
 
Posts: n/a

Default Re: How to fill empty column with number sequence? - 02-13-2004 , 03:20 AM






Hello Ken,

update <table> set pk_f = seq.nextval;

For big and active tables use PL/SQL block.

Regards,

Ron
DBA Infopower
http://www.dbainfopower.com
Standard disclaimer:
http://www.dbainfopower.com/dbaip_ad...isclaimer.html



"Ken1" <ken1 (AT) tjohoo (DOT) se> wrote

Quote:
I am going to drop a primary key from one column and create a new
column to be used as primary key in an existing database.
The old column was a date column which someone earlier though was a
good candidate for a primary key which we all know it's not.

Now I want to add a new field, i.e. called ID, with a normal number
sequence as primary key.

I have dropped the primary key, created the new column, created the
new sequence and created a trigger to generate the primary key for new
inserts.

But I don't know how to generate/update the new ID column with
sequence numbers for the already existing records.

Any ideas?

/Kenneth



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.