Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to setup a column to auto-increment

How to setup a column to auto-increment

Scheduled Pinned Locked Moved Database
databasesql-serversysadmintutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mundo Cani
    wrote on last edited by
    #1

    Hello, I have an identity column that is set up to auto-increment via the "Identity Increment" property for the column. This is working fine. However, I have another column that I'm calling "Sequence". This is not an identity column, it just specifies the position of each record which is subject to change. I want to set up the column to auto-increment so I don't have to manually enter the Sequence number for each record I add. Is there a way to set up a column to auto-increment without making the column an Identity column, and still allowing me to manually change the Sequence numbers later if I want? BTW: I'm adding data to the table in Microsoft SQL Server Management Studio. Thanks! Ian

    G S 2 Replies Last reply
    0
    • M Mundo Cani

      Hello, I have an identity column that is set up to auto-increment via the "Identity Increment" property for the column. This is working fine. However, I have another column that I'm calling "Sequence". This is not an identity column, it just specifies the position of each record which is subject to change. I want to set up the column to auto-increment so I don't have to manually enter the Sequence number for each record I add. Is there a way to set up a column to auto-increment without making the column an Identity column, and still allowing me to manually change the Sequence numbers later if I want? BTW: I'm adding data to the table in Microsoft SQL Server Management Studio. Thanks! Ian

      G Offline
      G Offline
      goyal manish
      wrote on last edited by
      #2

      Use follwing: objCol.AutoIncrement = true; objCol.AutoIncrementSeed = 1; objCol.AutoIncrementStep = 1; objCol.ColumnName = "ID"; :)

      M 1 Reply Last reply
      0
      • G goyal manish

        Use follwing: objCol.AutoIncrement = true; objCol.AutoIncrementSeed = 1; objCol.AutoIncrementStep = 1; objCol.ColumnName = "ID"; :)

        M Offline
        M Offline
        Mundo Cani
        wrote on last edited by
        #3

        Thanks for the reply. I should have specified that I'm creating the table in Microsoft SQL Server Management Studio. These column properties don't seem to be exposed in the table designer. At least I can't find them... Ian

        1 Reply Last reply
        0
        • M Mundo Cani

          Hello, I have an identity column that is set up to auto-increment via the "Identity Increment" property for the column. This is working fine. However, I have another column that I'm calling "Sequence". This is not an identity column, it just specifies the position of each record which is subject to change. I want to set up the column to auto-increment so I don't have to manually enter the Sequence number for each record I add. Is there a way to set up a column to auto-increment without making the column an Identity column, and still allowing me to manually change the Sequence numbers later if I want? BTW: I'm adding data to the table in Microsoft SQL Server Management Studio. Thanks! Ian

          S Offline
          S Offline
          shm53
          wrote on last edited by
          #4

          You caqn not have more that one identity column per table. The way to handle what you are attempting may be to insert the new record, get the identity using the SCOPE_IDENTITY() function then updating the record with that value

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups