Inspecting a rather critical database that is used by some software on my system, I found that one of the tables had a primary key on the column Id
, where Id
is calculated using checksum(newid())
. This makes me feel uneasy; the newid
s are guaranteed to be unique, but by applying the checksum (to a 32-bit integer, presumably for performance reasons?), you have some chance that you get a collision (with 1M rows in the table, I'd put that chance at around 1:4000, too much for my liking).
So:
- Am I missing some crucial bit of information that says the above is actually okay?
- If not - what happens if the application tries to insert a new row into the table and the
checksum(newid())
gives a primary key that already exists? Will my table blow up? Will the insert fail and leave it up to the application what to do with it?