Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Create random number
Message
De
03/06/2012 12:16:46
Thomas Ganss (En ligne)
Main Trend
Frankfurt, Allemagne
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01545107
Message ID:
01545186
Vues:
51
>>Sort of. Do you want to create a random number for every row or a single value? RAND() function will return the same value for all rows in the result, so you need to use checksum(NewID()) in order to generate random value for every row.
>>
>>Check this article by Pinal Dave
>>http://blog.sqlauthority.com/2007/04/29/sql-server-random-number-generator-script-sql-query/
>
>I want/need to create just one random number for the current row, when Inserting a record. This is not a PK field but still, for business purpose, needs to have a unique entry. So I don't think that I would need to use checksum().

Uuhm,

unique entry negates "true" randomness
even for pseudo random distributions like the machine generated ones...

If you need it for sampling or statistical work,
allow duplicate numbers and work via set instead of creating a unique value.

regards

thomas
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform