Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem using GETDATE() to generate a key
Message
De
22/08/2013 07:14:05
 
 
À
22/08/2013 06:56:39
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01580950
Message ID:
01580956
Vues:
33
>>>Hi
>>>
>>>I'm dealing with a system that in one area uses keys generated keys using GETDATE().
>>>
>>>This is producing duplicates sometimes.
>>>
>>>If I select GETDATE() in a loop it returns the same datetime through a lot of iterations . How often is the date and time refreshed and what sort of delay would I need to introduce to ensure I got a new date and time on each key generation.
>>>
>>>
>>>Thanks
>>
>>Think the precision is one millisecond
>>
>>Don't think a datetime is a good idea for a key.
>>
>>Can you use a guid type field and use newsequentialid() ) to obtain a new key ?
>
>Hi Gregory
>
>its not my data. I'm loading data into a table thats normally populated by a different system and I'm emulating what that other system does to build a key.


I see that your key is 20 chars. Try using SYSDATETIME(). There are 7 digits after the decimal point (GetDate() only has 3)

eg
TWEB_AUTO.....
would become
TWEB_
and you have room for the extra 4 digits
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform