Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


IDENTITY value becoming too big


IDENTITY value becoming too big

Author
Message
Casper101
Casper101
SSC-Enthusiastic
SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)

Group: General Forum Members
Points: 131 Visits: 1200
I have a table that gets a fresh set of data from our source each day. This mean I DELETE almost all the records each day and repopulate it with new data.
I do not TRUNCATE the table because according to business rules all the records can't be deleted, so my script is:
DELETE FROM Table1
WHERE .....

This deletes almost all the records each day.

Being a DELETE, this means the primary key column, which is an IDENTITY, does not get reseeded but rather this values just keeps getting bigger and bigger.

I am running into a scenario where the INT data type on this IDENTITY column is going to become too small.
My ID column is on 1,500,254,112 and the maximum for an INT is 2,147,483,647.

Now before I just go and change the data type to a bigint, I was hoping someone could give me a better solution to keep the ID value in check?

Any suggestions?
John Mitchell-245523
John Mitchell-245523
SSCertifiable
SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)

Group: General Forum Members
Points: 7468 Visits: 15142
Presumably your identity seed is 1? You could set it to -2,147,483,647. That would double your capacity - I don't know whether that would be enough?

John
Vishal.Gajjar
Vishal.Gajjar
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: 1337 Visits: 701
You can use DBCC CHECKINDENT to reseed identity value.

DBCC  CHECKIDENT ('Production.Product' , RESEED, 1001)



Vishal Gajjar
http://SqlAndMe.com
HowardW
HowardW
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1211 Visits: 9892
Presumably, the rows you're not deleting each day are the highest ID values in the set? If so, simply reseeding wouldn't help. There are obviously convoluted solutions involving deleting, updating the IDs of the existing rows back to lower IDs, then reseeding, or moving rows out and truncating/reinserting but seems like overkill.

Bigint isn't so terrible, I'd just check whether you actually need an identity on the table at all first. Could another column serve as the PK instead (assuming you're using the identity as a PK)?
Gazareth
Gazareth
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2872 Visits: 5351
Hi,
You can use DBCC CheckIdent to reseed the column, assuming the values aren't used elsewhere in the database?

To avoid this in the future you could remove the identity property and insert with rownumber(), that way each insert will start at 1.
Casper101
Casper101
SSC-Enthusiastic
SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)

Group: General Forum Members
Points: 131 Visits: 1200
Hi,

Yes HowardW, you are correct - reseeding won't work because of the records and their relevant ID values that remain after the DELETE.
I was also thinking of the possibility of updating the ID values etc as suggested by you, but just did not know if all that work is really the best solution.

Thanks for your feedback! Smile
John Mitchell-245523
John Mitchell-245523
SSCertifiable
SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)SSCertifiable (7.5K reputation)

Group: General Forum Members
Points: 7468 Visits: 15142
Do you have any other tables that reference the identity column on this table? For example, are there any foreign key constraints?

John
Steve Jones
Steve Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: Administrators
Points: 36162 Visits: 18751
Answer John's question, and then go to BIGINT. I had to do this in a system doing scans of our nodes every hour. We ran out of INTs in about 8 months.

Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Casper101
Casper101
SSC-Enthusiastic
SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)SSC-Enthusiastic (131 reputation)

Group: General Forum Members
Points: 131 Visits: 1200
Hi,

Yes I do have tables that reference this ID Primary key column.
So I guess I will go to BIGINT then?

Thanks again everyone
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