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
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on May 16, 2020Comments
-
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 about 15 yearsThis is for SQL Server by the way.
-
KM. about 15 yearsI'd bet sql server since it is asp.net
-
Ropstah about 15 yearsI do .NET with Oracle, see my other answer. I was just assuming SQL Server somehow.....
-
Ape-inago about 15 yearsdid you mean to say "non-trivial"?
-
Admin about 15 yearsI expanded "Identity Specification" and try to edit "Identity increment" but I cannt do that, becuse it's not enlighten
-
Ropstah about 15 yearsFirst change "Is identity specification" to: Yes
-
Ropstah about 15 yearsdoubleclick NO, then it will turn into YES
-
Madusanka about 11 yearsdo not forget that the data type should be integer :)