Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting 14 random records
Message
 
 
À
22/07/2009 13:26:45
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:
01416780
Vues:
61
>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

In my case the first returned 0 rows and for 100 rows it returned 265 records.

http://msdn.microsoft.com/en-us/library/ms189108.aspx
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform