Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Create an AutoCounter Column in a Table in SQL 2008 R2?

There is nothing in the "Data Type" drop-down that indicates an auto-counter.
I selected int and I am assuming there is a setting somewhere else to turn it into an auto-counter.
The idea is to have a 100% unique ID for my primary key, and every time a row is added it gets the next available ID number assigned to it.

http://img64.imageshack.us/img64/2472/primarykey.png

like image 891
Giffyguy Avatar asked Dec 28 '22 03:12

Giffyguy


1 Answers

What you're after is called IDENTITY in SQL Server terminology.

The column must be a numeric data type (INT typically, check the range of values to what suits your needs) before you can set the column to be IDENTITY -- you can see the listing in your screenshot, under Table Designer. There can only be one IDENTITY column per table -- this will change in SQL Server 2011 when they start support of sequences.

like image 131
OMG Ponies Avatar answered Mar 16 '23 00:03

OMG Ponies