Dieser Post wurde aus meiner alten WordPress-Installation importiert. Sollte es Darstellungsprobleme, falsche Links oder fehlende Bilder geben, bitte einfach hier einen Kommentar hinterlassen. Danke.
Sybase ASE Express Edition is an enterprise level database server - for free. It recovers (usually) flawless from any unclean shutdown (server reset/power outage), but the identity column counters usually skip big after recovery leaving huge gaps in the numbering.
Sybase does this skip for the right reasons - to keep data consistency, but having a 50.000.000 items gap isn't what you usually want. Here is a short tutorial on how to fix this (everything which has a $ sign in front of it is a variable, replace it by your value):
- Connect to the database using isql or interactive SQL
- Issue a use $databasename command to select your database
- Use SELECT next_identity('$tablename') to find out the value of the next row being inserted
- Use SELECT TOP 10 $identity_column FROM $tablename ORDER BY $identity_column DESC to see the numbers of the newest rows. Usually this translates to SELECT TOP 10 id FROM $tablename ORDER BY id DESC
- If your next_identity value is 500 and the highest used id is 499, everything is fine, skip to step 3 and the next table, if the next_identity is something like 500233 and your highest id is like 229 or 235, you may reset the next_identity value
- Use sp_chgattribute $tablename, 'identity_burn_max', 0, '$new-identity-value' to set the next_identity value for this table.
- Go to step 3 for the next table if everything goes well.
- If Sybase ASE issued an error like "The value 31295 for 'identity_burn_max' attribute must be greater than or equalto the current maximum identity value 3000008085.", think about your identity gap. If one of the following is true for you, there is no (easy) way to change the next_identity counter:
- You might ever (in 10 years or so) fill the gap between the new next_identity value you'ld like to set and the next used value. You'll run into really big trouble (and I mean BIG trouble) if this ever happens!
- Having the gap is a visual thing only, there are no technical reasons (like too small variables in software).
- Continues numbering is not important at all.
- If you're sure you need to change the next_identity value, use dbcc set_identity_burn_max($databasename, $tablename, '$new-identity-value') to force setting of a new next_identity value.
2 Kommentare. Schreib was dazu-
Olivier DETRY
2.09.2011 17:27
Antworten
-
rosa
28.06.2012 14:38
Antworten
Thank you very much !
the command
dbcc set_identity_burn_max($databasename,$tablename, ‘$new-identity-value’)
saved me may time :)
Thank you so much!! It works awesome :)