PDA

View Full Version : auto-increment identity column


BobLewiston
03-25-2009, 12:08 AM
Using Visual C# 2008 Express and SQL Server 2008 Express, I would like to insert new records into database "AdventureWorks", table "Person.Contact".

To my surprise, this table's int-value identity column "ContactID" does not appear to be auto-increment. I don't know how to confirm for sure that this is so. (I have installed SQL Server Management Studio, if that helps.)

How can I confirm this, and how can I make ContactID auto-increment?

And incidentally, will auto-increment just start incrementing from the highest existing ContactID, or will it first use lesser ContactID values that are absent from the table (presumably due to deletions)?

Old Pedant
03-25-2009, 01:02 AM
Well, I only have the Express version of MSSM, but I would expect the answer to be the same or nearly so.

Open up the DB in question.
RIGHT CLICK on the table in question and click MODIFY (you're not really going to mod)
In the list of columns that appears, click on the one you think should be an IDENTITY column.

There should be a COLUMN PROPERTIES window/subwindow appear.
Scroll down in the properties and you should find an entry labeled IDENTITY SPECIFICATION. Expand it to see all the properties (or lack thereof) of the IDENTITY for this column.

90% sure if you convert a non-identity column to identity that it starts incrementing after largest existing value. Yeah, I just tested it. Make that 100%.

BobLewiston
03-25-2009, 04:41 AM
Old Pedant:

In SQL Server 2008 Management Studio Express, the route to Identity Specification is somewhat different: expand table, expand Columns or Keys, right-click identity column, click Modify, in lower right frame scroll down to Identity Specification, expand it.

Three options appear: (Is Identity), Identity Increment and Identity Seed, which are set to Yes, 1 and 1, respectively.

So are you saying I should toggle (Is Identity) from Yes to No and back again to turn on auto-increment?