Forum Discussion
Alexander Wurzinger
Jul 20, 2021Copper Contributor
Checking in Script if Identity has be nused
Hi, Is it possible to check in a SQL-Script if a Identity of a Table has ben used before? My reason for asking is, that I need to reset the Seed of a Table, witch as dokumentet works with 'CHECK...
AnatoliD
Jul 21, 2021Copper Contributor
Seems there is no other way to get this info;
CHECKIDENT does not work as documented; and it is not only issue with it. (There were complains that it is not thread-save/transaction-safe).
You would need to shop workarounds,
1) Use a PowerShell script where you can capture and parse DBCC output.
2) Always use truncate instead of check.
3) Consider to use SEQUENCE instead.
https://www.sqlshack.com/difference-between-identity-sequence-in-sql-server/
Alexander Wurzinger
Jul 21, 2021Copper Contributor
AnatoliD
Thanks for the answer, but sadly neither of the 3 is a option for the thing I wanted to do.
It would also work if there was a sure/reliable way to get the next ID, but I didn't find any.
Thanks for the answer, but sadly neither of the 3 is a option for the thing I wanted to do.
It would also work if there was a sure/reliable way to get the next ID, but I didn't find any.