unique filed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rsnihar
    New Member
    • May 2007
    • 2

    unique filed

    Hi all,
    In an existing table I want to make a unique field and the values starting with 1 would be incremented by one till end of the filed. How to do it?
  • frozenmist
    Recognized Expert New Member
    • May 2007
    • 179

    #2
    Hi,
    Have an identity column when creating the table. It will auto increment the value with what is specified
    identity(seed,i ncrement)
    seed is the first value and increment is by how much you want it incremented for the next row

    eg:
    CREATE TABLE TABLE1
    (
    id_num int IDENTITY(1,1),
    name varchar (20),
    )

    Hope that helps
    Cheers

    Comment

    • rsnihar
      New Member
      • May 2007
      • 2

      #3
      Hi.. but I have an existing table.. wht to do in this case..



      Originally posted by frozenmist
      Hi,
      Have an identity column when creating the table. It will auto increment the value with what is specified
      identity(seed,i ncrement)
      seed is the first value and increment is by how much you want it incremented for the next row

      eg:
      CREATE TABLE TABLE1
      (
      id_num int IDENTITY(1,1),
      name varchar (20),
      )

      Hope that helps
      Cheers

      Comment

      • frozenmist
        Recognized Expert New Member
        • May 2007
        • 179

        #4
        Hi,
        You can user alter table and add a column
        [code=sql]
        Alter table <tablename> add ID int identity(1,1)
        [/code]

        Hope it helps
        Cheers

        Comment

        Working...