Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identity Seed Auto increment record

Status
Not open for further replies.

dctechuser

Technical User
Sep 11, 2009
9
US
Hi,

I have a question about adding records to the SQL Server 2005 database. I have an ID field that automatically increments. When I first add records to the table, it is placing a "0" in this field. Why doesn't the field start at 1 in lieu of 0? Other people have added records to the table, but this is my first time in using my name on the login. When I add the record the record shows the ID as the next incremented number which is 163 when it is saved.
I came out and came back in and now enter a record it shows the next incremented number when I add the record as 164.

Just want to understand what is happening. Any explaination is helpful. Juts curious.

Thanks
 
Why does it start at 0 instead of 1? I don't know but I'd guess since VB.Net defaults to a lowerbound of 0 in most cases why not stick with the convention?

Why does it start at 0 instead of 164? Well, when you start up the application, if the application doesn't initially know what number the database "is on," then it can't start at 164. Note that even if it did know what number the database was on, someone else could add another record to the database before you add yours. So it wouldn't be up to date because the data in your application is stored in the memory on your pc and only reconciles with the database when certain operations occur.

Why does it change from 0 to 164? When your data is reconciled to the database, it gets that information back from the database after the insert.
 
Riverguy,

I just wanted to be sure nothing was wrong with my application showing the 0 when I add a record with my login. I never have added a record to the database. This is my first time. Others have added records, but when I save my information added it shows the next record in sequence added which is 164.

I was just wondering why the ID field showed 0 when I click the add button.

I made the ID field automatically increment in the property design on the 2005 server for the ID field. The Identitiy seed is set to increment by 1.

Dataman86
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top