Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 auto-increment identity column

Author  Topic 

BobLewiston
Starting Member

29 Posts

Posted - 2009-03-24 : 19:15:43
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)?

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2009-03-24 : 19:27:36
In SQL management studio, in the object explorer window, expand ServerName->Databases->AdventureWorks->Tables->Person.Contact->Columns. Then, right click on ContactID and select Properties from the popup menu. In the window that will appear, if Identity is set to True, it is an identity column.

You can change the identity property right click on Person.Contact and select Design.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-03-24 : 19:28:15
The GUI way is to right click on the table, select "Design", highlight the column, check the "Identity Specification" field. You can change its property there too.

An identity will increment from the value returned by DBCC CHECKIDENT, which is typically the highest value. It will not fill in "gaps" due to deletes/updates.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-03-24 : 19:28:43


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -