Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Making Transaction ID's

Author  Topic 

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2005-02-01 : 21:48:07
I just want to ask this...

is it ok that i will use this sql to generate a transaction ID. I want to make a unique transaction ID. Does the result of this is unique?

declare @a as float
set @a = cast(getdate() as float)
select @a


the result is saved on a field with varchar datatype...





Want Philippines to become 1st World COuntry? Go for World War 3...

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-02-01 : 22:49:37
It won't be unique if you are inserting more than one row at a time (GetDate() would be evaluated only once for the entire set), or if you have multiple sessions working at the same time.

Not to mention that floats are approximate values and may not be precise enough for a unique key. Plus you gain nothing, and waste space, by converting it to varchar.

If you want an efficient alternative to using a GUID:

http://www.informit.com/articles/article.asp?p=25862

He describes a technigue that combines GetDate() and NewID(). You could probably modify it to use only 8 bytes instead of 16, and you'd still get unique (and incrementing) ID's.
Go to Top of Page
   

- Advertisement -