Reputation: 1141
I've some questions regarding the SQL Server IDENTITY
auto-incremented column.
Does someone know if that field is thread-safe?
Can I use SQL Server IDENTITY
column in a multitask application that attempt to parallel insert some records with an IDENTITY
auto-incremented column?
Do you have any docs link about that?
Upvotes: 2
Views: 1099
Reputation: 171206
It is thread-safe in the sense that every number will be handed out at most once. Numbers can be skipped, though.
This is a well-accepted fact. SQL Server would be garbage if this was not so. It is the point of identity fields to hand out unique values.
Be aware that you can circumvent these guarantees by reseeding the column. That way you can have it hand out whatever you want.
Also note, that an IDENTITY
constraint does not enforce uniqueness of values in that column.
Upvotes: 3