I am trying to generate a unique ID for the primary key of a table and I am using DateTime.Now.Ticks
for it. That\'s a requirement for now we can\'t use Ident
TL;DR:
The precision of DateTime.Now
is around 15ms, if you loop faster than that, DateTime.Now
will have the same value over differents iterations.
As described in the .Net source code:
The data is stored as an unsigned 64-bit integeter
Bits 01-62: The value of 100-nanosecond ticks where 0 represents 1/1/0001 12:00am, up until the value 12/31/9999 23:59:59.9999999
Furthermore, the DateTime.Now is quite imprecise:
The resolution of this property depends on the system timer, which is approximately 15 milliseconds on Windows systems
For the ID assignation part, as other stated, use GUID
which have been made for this purpose.