Sunday, July 06, 2008    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< May 2006 >>
S M T W T F S
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Search

Categories
 • Adobe (63) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (10) [RSS]
 • AIR (108) [RSS]
 • Appearances (112) [RSS]
 • Books (66) [RSS]
 • CFEclipse (14) [RSS]
 • ColdFusion (1105) [RSS]
 • Data Services (6) [RSS]
 • Flash (94) [RSS]
 • Flex (334) [RSS]
 • Jobs (86) [RSS]
 • JRun (12) [RSS]
 • Labs (27) [RSS]
 • LiveCycle (16) [RSS]
 • MAX (145) [RSS]
 • Regular Expressions (12) [RSS]
 • SQL (36) [RSS]
 • Stuff (496) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (132) [RSS]
 • Wireless (96) [RSS]

Other BLOGs
 • Ray Camden
 • Tim Buntel
 • Sean Corfield
 • John Dowdell
 • Steven Erat
 • Brandon Purcell
 • Charlie Arehart
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Day : May 26, 2006 / Main
May 26, 2006

Using TABLESAMPLE To Retrieve Partial Resultsets

I just discovered a new SELECT clause that has been added to T-SQL in SQL Server 2005. TABLESAMPLE can be used to return a sampling of rows (either a fixed number or a specified percent of the table rows). Here is how it is used:
/* Get a sample 5 rows */
SELECT *
FROM table
TABLESAMPLE (5 ROWS)

/* Get a sample 10 percent of rows */
SELECT *
FROM table
TABLESAMPLE (10 PERCENT)
It is worth noting that you may not get the exact number of rows that you'd expect. Sampling occurs by table page, and the number of rows in a page can vary.

TrackBacks
There are no trackbacks for this entry.

No trackback URL. Trackbacks are only allowed via interactive form.

Comments
Another new function they added and I find really cool is that you can now use TOP with a DELETE.
# Posted By tof | 5/28/06 7:51 PM
As a point of reference in SQL 2000 you can do this with the newid() function.

select top 5 *
from table
order by newid()
# Posted By intj | 5/30/06 11:34 AM
Well, Tablesample is a great sampling method.

But I could not get it working with table variable.

Here is the TSQL

declare @test table
(
id int identity(1,1),
test_count int
)

insert into @test values(1)
insert into @test values(2)
insert into @test values(3)
insert into @test values(4)
insert into @test values(5)
insert into @test values(6)
insert into @test values(7)
insert into @test values(8)
insert into @test values(9)
insert into @test values(10)
insert into @test values(11)

select * from @test tablesample(10)

select * from @test tablesample(5 rows)

select * from @test tablesample(40 percent)

Nothing works!
# Posted By abhi | 8/3/07 5:40 PM

  © Copyright 1997-2008 Ben Forta, All Rights Reserved