Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting 14 random records
Message
De
22/07/2009 13:26:45
 
 
À
17/02/2009 18:16:33
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:
01382524
Message ID:
01413751
Vues:
63
Michel, unless someone else has posted this....another approach: in SQL 2005 there is a new TABLESAMPLE statement to get a sampling based on # of rows or sampling based on %.
USE AdventureWorks ;
GO
SELECT FirstName, LastName
FROM Person.Contact 
TABLESAMPLE (10 rows) ;
TABLESAMPLE is particularly nice for grabbing a %.....and I'm guessing is faster than using NEWID...however, there are a few gotchas...

- Newid is probably better than this approach, if your sampling includes joins
- If your table is large enough and the sampling is small enough (e.g. 5,000 rows and 10 rows), TABLESAMPLE might not return anything. So you may have to restort to...
USE AdventureWorks ;
GO
SELECT top 10 FirstName, LastName
FROM Person.Contact 
TABLESAMPLE (500 rows) ;
If NEWID works fine for you on large tables, I'd go with NEWID....but if you run into performance or other issues, this might be worth a try
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform