SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


IDENTITY(1,1) doesn't work, from 17 jumped to 1001


IDENTITY(1,1) doesn't work, from 17 jumped to 1001

Author
Message
mario17
mario17
SSC-Addicted
SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)

Group: General Forum Members
Points: 494 Visits: 683
Hi,
I have a table with PK column defined like IDENTITY(1,1), it has 16 entries, now after series of migration and restores I'm adding new row into it like below and get new TypeID = 1001 ? Totaly lost is this somewhere go reset to 1000? Before was only 16 entries with correct sequence 1 by 1 thru 16.

What could be wrong , can anybody help.

Best M


CREATE TABLE [dbo.].[Types](
[TypeID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[Code] [nvarchar](350) NULL,
[Description] [nvarchar](350) NULL,
[IsActive] [bit] NOT NULL,

CONSTRAINT [pkTypes] PRIMARY KEY CLUSTERED
( [TypeID] ASC ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] )

INSERT dbo.Types
( Code ,
Description ,
IsActive
)
VALUES ( N'Alpha' , -- Code - nvarchar(50)
N'Alpha Type 17' , -- Description - nvarchar(250)
1 -- IsActive - bit )

select * from dbo.Types



TheSQLGuru
TheSQLGuru
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13289 Visits: 8566
If you shut down SQL Server there is a known bug that advances the identity values. I don't know if there is a fix for that or not.

Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
TheSQLGuru
TheSQLGuru
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13289 Visits: 8566
Here is a link with more information:

http://connect.microsoft.com/SQLServer/feedback/details/739013/failover-or-restart-results-in-reseed-of-identity

Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
Cody Konior
Cody Konior
SSC-Addicted
SSC-Addicted (449 reputation)SSC-Addicted (449 reputation)SSC-Addicted (449 reputation)SSC-Addicted (449 reputation)SSC-Addicted (449 reputation)SSC-Addicted (449 reputation)SSC-Addicted (449 reputation)SSC-Addicted (449 reputation)

Group: General Forum Members
Points: 449 Visits: 1105
Also remember that if you begin a transaction and rollback, the identity values will also have increased afterwards. That makes sense if you think about it.

Identity is a count of attempted inserts, not consecutive sequential numbers. AFAIK you can't even really trust a sequence data type for that purpose either.

You can do a DBCC CHECKIDENT(blah, RESEED) to reset it to the next available number though.
mario17
mario17
SSC-Addicted
SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)

Group: General Forum Members
Points: 494 Visits: 683
Thanks, all
Yes, I did reseed and it worked.

DBCC CHECKIDENT ('Person.AddressType', RESEED, 10);
GilaMonster
GilaMonster
SSC Guru
SSC Guru (92K reputation)SSC Guru (92K reputation)SSC Guru (92K reputation)SSC Guru (92K reputation)SSC Guru (92K reputation)SSC Guru (92K reputation)SSC Guru (92K reputation)SSC Guru (92K reputation)

Group: General Forum Members
Points: 92247 Visits: 45285
Bear in mind that identity has never been guaranteed to not have gaps. It's an ever-increasing number, that's all. It's not gap-free and it's not even guaranteed unique (you can reseed under the current max value)

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Perry Whittle
Perry Whittle
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21155 Visits: 17246
TheSQLGuru (3/31/2014)
If you shut down SQL Server there is a known bug that advances the identity values. I don't know if there is a fix for that or not.

according to MS it's not a bug, it's by design.

-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
Perry Whittle
Perry Whittle
SSC-Insane
SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)SSC-Insane (21K reputation)

Group: General Forum Members
Points: 21155 Visits: 17246
mario17 (3/31/2014)
Thanks, all
Yes, I did reseed and it worked.

DBCC CHECKIDENT ('Person.AddressType', RESEED, 10);

The problem here is, when the value jumped if identities were created in the upper range and you reseed back to 10, you'll have issues later

-----------------------------------------------------------------------------------------------------------

"Ya can't make an omelette without breaking just a few eggs" ;-)
brewmanz
brewmanz
Mr or Mrs. 500
Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)Mr or Mrs. 500 (567 reputation)

Group: General Forum Members
Points: 567 Visits: 406
Also note that with Replicated Tables you can/will also have gaps, as each subscriber of the published Table is pre-allocated a range of IDs it can use.
Dan Guzman - Not the MVP
Dan Guzman - Not the MVP
SSC Eights!
SSC Eights! (934 reputation)SSC Eights! (934 reputation)SSC Eights! (934 reputation)SSC Eights! (934 reputation)SSC Eights! (934 reputation)SSC Eights! (934 reputation)SSC Eights! (934 reputation)SSC Eights! (934 reputation)

Group: General Forum Members
Points: 934 Visits: 741
Gaps I don't mind, but really 1000 or 10,000 at a time? It's too much. I guess if you only reboot once a year then it won't matter much, but any more frequently than once a month, and you won't be able to read my invoice or order numbers any more.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search