r/SQL • u/clakshminarasu • 2d 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 1d 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 2d 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 2d ago
Did you consider refactoring with UUIDs (GUIDs in SS)?
3
u/Hour-Measurement-835 2d ago
Not sure if 1.5M a day is your peak or it's still climbing, but at 1.5M the negative half runs out in about 3.9 years. The 5 or 6 only works if you stay near 1M.
3
u/saucerattack 1d 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 2d 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 1d 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 11h ago
It works just fine, but immediately plan to migrate to bigint or maybe UUID.
1
u/freshrobin440 1d 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 1d 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 1d 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 2d 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.