Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Set column Identity value to 0, 1, and so on
Message
From
05/07/2016 10:51:45
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01637908
Message ID:
01637909
Views:
50
>Hi,
>
>I have a table in SQL Server that currently has NO rows/records. There is a PK column set to Identity Yes. I want to make this column values to start with 0 (zero). Here is what I did:
>1. Set Identity of this column to Off
>2. Added a record/row to this column and set the value to 0 (zero).
>3. Set Identity of this column back to On
>
>Now when I add a new record, SQL Server sets the value to this column as 2.
>
>How can I make it start with 1 (after I already added a record of 0)?
>

Here's what you "can" try...

http://blog.sqlauthority.com/2007/03/15/sql-server-dbcc-reseed-table-identity-value-reset-table-identity/

Having said that, this reminds me of conversations I had with my father. I'd ask, "Dad, can I do such and such?" His reply, "You could....but it would be wrong"

Unless there is some compelling reason, I don't recommend this. Identity values aren't supposed to have meaning. The only exception...sometimes you might have a sale for an undefined cost center. Instead of storing a NULL in the foreign key value in the fact table, I'll have an "undefined/unclassified" cost center in the cost center master, with an identity of -1....and store that in the fact table. That's about the only time I suspend identity generation...just long enough to jam a dummy -1 value into the master.

But beyond that, I leave identity generation and seeding alone.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform