How can I make a primary key as AUTOINCREMENT

37,241

Solution 1

There is a property "Identity Specification". Expand that one, you can chose Increment value, and Increment Seed

Solution 2

In Sql Server define the column like this...

[PrimaryID] [int] IDENTITY(1,1) NOT NULL

Then you can add a constraint making it the primary key.

Solution 3

Since you listed ASP.NET, I'm going to assume you are running a SQL Server 2005/2008. If you want to use the GUI, then follow these steps:

  • Open the table in design view
  • Click on the "ID" column
  • Confirm the type is an Int
  • Select "Yes" under Identity Specification
Share:
37,241
Admin
Author by

Admin

Updated on May 16, 2020

Comments

  • Admin
    Admin about 4 years

    I have table in Database and the primry key is 'ID', Just I want to ask how can I make it AUTOINCREMENT

    I know that's esay Q, but I dont know how can I do it.

    thanks

  • Ropstah
    Ropstah about 15 years
    This is for SQL Server by the way.
  • KM.
    KM. about 15 years
    I'd bet sql server since it is asp.net
  • Ropstah
    Ropstah about 15 years
    I do .NET with Oracle, see my other answer. I was just assuming SQL Server somehow.....
  • Ape-inago
    Ape-inago about 15 years
    did you mean to say "non-trivial"?
  • Admin
    Admin about 15 years
    I expanded "Identity Specification" and try to edit "Identity increment" but I cannt do that, becuse it's not enlighten
  • Ropstah
    Ropstah about 15 years
    First change "Is identity specification" to: Yes
  • Ropstah
    Ropstah about 15 years
    doubleclick NO, then it will turn into YES
  • Madusanka
    Madusanka about 11 years
    do not forget that the data type should be integer :)