Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2008
    Posts
    26

    Question Unanswered: primary key on a table

    i need to add a primary key on a table having record in it .this should also generate a unique ids for the existing records.i cant delete records from the table how can i achieve this task???????
    plz help ????????

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    use a SEQUENCE
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jan 2009
    Location
    Dhaka, Bangladesh
    Posts
    51
    1. create a sequence
    CREATE SEQUENCE test_id_seq INCREMENT 1
    MINVALUE 1 MAXVALUE 9999999999 START 1 CACHE 20;

    2. add a column to your table

    alter table test add column id number(10);

    3. insert sequence value to the column

    update test set id= test_id_seq.nextval ;

    4. add primary key

    alter table test add constraint test_id_pk primary key(id);
    Mohammad Hasan Shaharear
    E-mail
    Blog: http://shaharear.blogspot.com

Posting Permissions

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