Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2006
    Posts
    55

    Unanswered: inserting increment vaue in a table

    hi experts,
    i have a table that i did a lot of work with, now i want to add a column and this column has to automatically incremented, now if i change it and save then it will replace my table data to 0 and i do not want to lose all the data, is there a way to insert values like 1 2 3 4 5 6 to this table(Locations) without changing the other data?

    thanks a lot
    Peace out
    Mr joka

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Code:
    CREATE TABLE myTable99(Col1 int, Col2 char(1), Col3 datetime DEFAULT (Getdate()))
    GO
    
    INSERT INTO myTable99(Col1,Col2)
    SELECT 1, 'A' UNION ALL
    SELECT 2, 'B' UNION ALL
    SELECT 3, 'C'
    GO
    
    SELECT * FROM myTable99
    GO
    
    ALTER TABLE myTable99
    	ADD Col4 int IDENTITY(1,1)
    GO
    
    SELECT * FROM myTable99
    GO
    
    DROP TABLE myTable99
    GO
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Oct 2006
    Posts
    55
    hi Brett,
    thanks for your quick reply, i'm new in sql so can you explain more. my table name is Locations.

    many thanks
    Peace out
    Mr joka

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Have you run the above script in Query Analyzer?
    I suggest you do and tell us what you notice
    George
    Home | Blog

  5. #5
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    New to SQL server

    What Version are you using?

    Do you know what Books Online is?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  6. #6
    Join Date
    Oct 2006
    Posts
    55
    got it experts thanks, it is working good.

    i'm not realy new to sql

    thanks
    Peace out
    Mr joka

  7. #7
    Join Date
    Feb 2004
    Location
    Burbank & Santa Cruz de la Sierra
    Posts
    3,716
    Quote Originally Posted by mrjoka
    ...i'm new in sql...
    Quote Originally Posted by mrjoka
    i'm not realy new to sql

    WTF ?
    aka "Paul"
    Non est ei similis.

    I just read "100 Things To Do Before You Die". I was surprised that "Yell for help!!" wasn't one of them

  8. #8
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Where's the food?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  9. #9
    Join Date
    Feb 2004
    Location
    Burbank & Santa Cruz de la Sierra
    Posts
    3,716
    Most of the time...but sometimes Was That Funny?
    aka "Paul"
    Non est ei similis.

    I just read "100 Things To Do Before You Die". I was surprised that "Yell for help!!" wasn't one of them

Posting Permissions

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