Pham Nguyen (sherkaner77@yahoo.com) writes:
[quoted text, click to view] > Thanks - I have a few questions, though. What happens if the process
> that is calling this procedure to generate keys errors out? Wouldn't
> we want to be able to roll back the keys that have been generated?
That depends on your application. For our usage, this is perfectly
acceptable. If you want to roll back keys beause the transaction bailed
out, you will have to face a contention problem, since you cannot
commit until the keys have been used.
[quoted text, click to view] > Also, I'm not sure why the key table is emptied out every day, if the
> keys have to be unique across days.
Sorry, I forgot that our purpose is a bit special. We have a coupld of
so called aid-tables. They are permanent temp tables so to speak. That
is, they do hold transient data during some sort of process. They are
not temp tables because of performance problems, or because it's un-
suitable for the process for some other reason.
Our system has a night job, which can assume that when it runs, nothing
else runs in the database. One section in this night job, empties all
aid tables (in case there are some data left behind), as well as the
aidkeys table.
Obviously, if your keys are generated for a permanent purpose, you need
to maintain the table with the keys.
[quoted text, click to view] > Is using READ UNCOMMITTED to scan the key table while generating keys
> really bad? What sorts of problems can crop up?
Well, one problem is that two processes can get the aame key value.
That is, they both attempt the same key value, both find that it's not
in use, both try to insert, and only one will survive.
Have you considered uniqueidentifier? That is probably the easy way out.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server SP3 at