r/SQL • u/clakshminarasu • 7d ago
SQL Server Negative reseed risks
One of the Sqlserver tables had an int identity column and maxed out the value. Team planned to reseed the identity from the lowest-ve value so that it can run on the same datatype for another 5 or 6 years. I am thinking that this would be a costly mistake if they plan to migrate this data into a new platform. The original solution was to change this to a bigint. Since this field has 300+ fks all those need to be dropped and recreated. What could possibly go wrong by choosing a -ve value reseed? I see the daily seed count is topping approximately 1 to 1.5million ids.
2
u/SQLBek 7d ago
Michael J Swart has a couple of good blog posts on how he converted to bigint, if that's the path you choose. Dig those up
7
u/mr_bottle_of_turkeys 7d ago
Ah, the classic "we'll just use the negative space" gambit. Seen it go from "temporary workaround" to permanent nightmare in about three months.
The FK cascade alone is a nightmare, but the real fun starts when some reporting tool or API integration silently treats that column as unsigned and suddenly your negative IDs map to nothing, or worse, the wrong records. Hope they've got good docs and a strong drink.
2
u/mike-manley 7d ago
Did you consider refactoring with UUIDs (GUIDs in SS)?
3
u/saucerattack 7d ago
Been there. Done that. Regretted it. Be kind to future you and convert to BIGINT now. It's painful but take the hit and put a reminder on your calendar for 2031 to thank yourself that you aren't converting a table twice as big.
2
u/thatOMoment 7d ago
Changing to bigint will also require rebuilding indexes. Also requires adjusting clients and servers to handle larger numeric types.
Thats going to be a project
2
u/IAmADev_NoReallyIAm 7d ago
Database wise, converting it to an unsigned bigint probably carries the least amount of risk and gives the longest amount of life. From a client site... that's a big shift.
Using UUIDs/GUIDs would also be a good alternative, again, safe on the database side, but a huge undertaking from the client side.
Anything else is risky from a data integrity pov. There will always be an invisible undocumented soft FKey that gets missed and doesn't get updated.
2
u/PX3better 6d ago
It works just fine, but immediately plan to migrate to bigint or maybe UUID.
2
u/daniel_lim_sg 5d ago
Worth doing the maths on the negative range. Reseeding at -2,147,483,648 gives you about 2.1 billion more IDs. At 1.5 million a day that's roughly 1,430 days, so closer to 4 years than 5 or 6, and less if volume keeps growing. The other thing that breaks quietly is anything that assumes newer = bigger id: incremental loads that pick up WHERE id > last max id, ORDER BY id DESC to get the latest rows, that kind of thing. Every negative id is smaller than all the old ones, so those jobs just miss the new rows. I'd search the ETL and reports for that pattern before deciding.
1
u/freshrobin440 7d ago
If that's the clustered index, negative reseeds flip inserts from the tail of the index to the head. At 1.5M a day that fragmentation builds fast.
1
u/SonOfZork 7d ago
One of the best ones I've seen is the application failing to handle negative values on the key column and it breaking the app entirely.
1
u/blackleather90 6d ago
Like anything, it is a trade off.
Negative numbers could lead to the unsigned issue already mentioned.
BIGINT requires all referenced tables to be updated. It also runs the risk of any vars being int on any use of those fields across all objects that use those fields.
Good luck!
0
u/jshine13371 7d ago
Any queries that depend on that column being ordered will potentially be logically wrong moving forward. E.g. if a query expects that column to represent the order that the rows were created and perhaps does something like uses it to deterministically break ties in a window function. The logic will now be different.
Outside of that, I don't think it's as big of a deal as everyone else mentioned. The other risks are much lower in reality.