Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have a simply table with 4 columns:

Food_Id
Food_Name
Calories
Food_Type


I am making a small app to be able to add data to the database. I need to be able to set the primary key (Food_Id) to be auto incremented however all the options for auto incremeted are greyed out and unavailble for selection.

So the simply question is how do I auto increment a primary key?

Thanks in advance
Posted
Comments
Corporal Agarn 3-Jun-11 14:54pm    
Please watch using the word database. Although you are adding data to a database you are putting it into a table.

1 solution

Easy:
When you create the field (I assume you are using SQL Management studio), give it an int datatype, then look in the properties for "Identity Specification". Click on the "plus" sign to it's left to expand the tree.
Double click on "Is identity" and it will change from "No" to "Yes".

It is now a autoincrementing field, and the options are available.

[edit]

Just realized, if you are doing this in VS, then the principle is the same:
Create the feild as an Int, then change "Identity" to "true". The options are available then.

OriginalGriff
[/edit]

[edit2]Doh! "Not" changed to "Now" - OriginalGriff[/edit2]
 
Share this answer
 
v3
Comments
DanHodgson88 3-Jun-11 10:08am    
Cheers, literaly just found it the option to change identity to true as I was checking the reply. Appreciate the reply :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900