home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.oracle      Overblown overpriced overengineered SHIT      2,288 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 1,086 of 2,288   
   boa to All   
   Re: How to fill empty column with number   
   13 Feb 04 23:00:32   
   
   From: root@localhost.net   
      
   Ken1 wrote:   
   > 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?   
      
   How about using rownum to generate id's for the existing rows?   
      
   alter table foo add bar number;   
   update foo set bar = rownum;   
      
   Remember to create the sequence with the proper "START WITH" number,   
   which should be max(bar) + 1.   
      
   HTH   
   Boa   
      
   >   
   > /Kenneth   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca