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
UDP Broadcaster
UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)

Group: General Forum Members
Points: 1446 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
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33039 Visits: 8680
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
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33039 Visits: 8680
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
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1073 Visits: 1110
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
UDP Broadcaster
UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)UDP Broadcaster (1.4K reputation)

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

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

Group: General Forum Members
Points: 230282 Visits: 46344
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 Guru
SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)

Group: General Forum Members
Points: 55575 Visits: 17709
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 Guru
SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)

Group: General Forum Members
Points: 55575 Visits: 17709
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
Right there with Babe
Right there with Babe (771 reputation)Right there with Babe (771 reputation)Right there with Babe (771 reputation)Right there with Babe (771 reputation)Right there with Babe (771 reputation)Right there with Babe (771 reputation)Right there with Babe (771 reputation)Right there with Babe (771 reputation)

Group: General Forum Members
Points: 771 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
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1340 Visits: 751
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