SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    192
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Add new PK column

    Hello,
    I have a SQL CE 3.5 database table having 35000 records. like
    Code:
    Name  Age Sex
    abul     21    M
    babul   22    M
    cabul   23    F
    .......................
    zabul   23    M

    I want to add an Auto_increment (Identity) Primary Key 'Id'

    Code:
    Id          Name Age Sex
    1           abul     21    M
    2           babul   22    M
    3           cabul   23    F
    .....................................
    35000     zabul   23    M
    what will be the query?

    Thanks

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    without playing around with sample data, i'm not sure

    you definitely don't want to be playing around with live data in case you screw it up

    if i were doing it, i would do what i've done several times successfully before -- create a new table with the identity column, do an INSERT SELECT to load it from the current table, then drop the current one and rename the new one
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Tags for this Thread

Bookmarks

Posting Permissions

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