SQL Apprentice Question
I have a table that has a computed value in the primary key (int column).
The computed expression is below:
(convert(int,(rand() * power(2,30))))
Does anyone know how I can get the last inserted value on this table since I
can't use @@IDENTITY. Thanks.
Celko Answers
What you have will fail because of duplication. Use additive congrunce instead.
http://www.rationalcommerce.com/resources/keys.htm http://www.rationalcommerce.com/resources/surrogates.htm http://www.rationalcommerce.com/resources/lfsr.gif
The formula is easy for a 31-bit number, always gives a unique answer and you will have the last number in a one-row table that will stay in main storage.
Monday, May 29, 2006
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment