Using "Now" as a unique index

B

Bob Day

Using VS 2003, VB.Net, MSDE....

Question 1) Can DateTime be used as a unique index?

Looking at a table's data via Server Explorer, someting like "Now" is only
displayed to the
second, but is it acually stored to the millisecond? Do all computations
calculate to the millisecond?

Either way, it would seem that this would not be a unique index, because two
updates could occur in the same second (or even millisecond).

I have tried things like the following, but they do not create unique
indexes.
Dim Unique_Index As String = Nothing
With Now
Unique_Index = .Year & .Month & .Day & .Hour & .Minute & .Second &
..Millisecond
Unique_Index = .Ticks
End With

Thanks!

Bob
 
W

William Ryan eMVP

Bob:

It 'could' be used for one, but that doesn't make it a good candidate. Even
if it was to the millisecond x10, the server's clock could change and things
could get reset. If you need it to be unique, perhaps an identity column
coupled with Now() would probably be better. Also, use Now as a default
value not as a formula b/c if it's a formula then everything in the column
will be the same.

--
W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top