update a null column with a sequence number
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 9 of 9

Thread: update a null column with a sequence number

  1. #1
    Join Date
    Dec 1999
    Location
    Purgatory
    Posts
    346

    update a null column with a sequence number

    So, just back from the pub after dinner........

    Got a table that is populated with 500K records. Requirement is to add a new column PURN, and populate it with a sequential number starting at 12 million.

    So PURN would go from 12,000,000 to 12,500,000

    Can't reload table, so must update in situ....

    Help!!

    Not that urgent by the way........

  2. #2
    Join Date
    Sep 2002
    Location
    England
    Posts
    7,333
    create sequence xxx starting with 12000000

    then loop round updating ther column with next val

  3. #3
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    update t set new_Col = 12000000 + rownum;
    select max(t) from t;
    create sequence t_seq start with ;
    Jeff Hunter
    marist89@yahoo.com
    http://marist89.blogspot.com/
    Get Firefox!
    "I pledge to stop eating sharks fin soup and will not do so under any circumstances."

  4. #4
    Join Date
    Dec 1999
    Location
    Purgatory
    Posts
    346
    Thanks Guys, went for Jeff's simple rownum solution.

    Old Peculiar has a way of clouding the mind......

  5. #5
    Join Date
    Jul 2002
    Location
    Northampton, England
    Posts
    612
    Speckled Hen has a way of making you fall asleep at your desk...

  6. #6
    Join Date
    Nov 2002
    Location
    Geneva Switzerland
    Posts
    3,142
    Consider yourselves lucky. Some of us make do with lager and the occasional bottle of Newcastle Brown.

  7. #7
    Join Date
    Sep 2002
    Location
    England
    Posts
    7,333
    you a geordie dapi?

  8. #8
    Join Date
    Jan 2000
    Location
    Chester, England.
    Posts
    818
    Why can't I work near a pub?

    I'll have a Guinness, by the way.

  9. #9
    Join Date
    Nov 2004
    Location
    Mexicali.Mexico
    Posts
    13
    Originally posted by marist89
    update t set new_Col = 12000000 + rownum;
    select max(t) from t;
    create sequence t_seq start with ;
    An easiest way is:

    1. Create sequence starting on 12000000.
    2. Add column to table
    2. Update table column in a single DML:

    UPDATE t
    SET x_column = t_seq.nextval;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width