Skip to main content
select top 10 percent * from [yourtable] order by newid() 

In response to the "pure trash" comment concerning large tables: you could do it like as athis to improve performance alternative.

select * from [yourtable] where [yourPk] in (select top 10 percent [yourPk] from [yourtable] order by newid()) 

The cost of this will be the key scan of values plus the join cost, which on a large table with a small percentage selection should be reasonable.

select top 10 percent * from [yourtable] order by newid() 

In response to the "pure trash" comment concerning large tables you could do it like as a performance alternative.

select * from [yourtable] where [yourPk] in (select top 10 percent [yourPk] from [yourtable] order by newid()) 

The cost of this will the key scan of values plus the join cost, which on a large table with a small percentage selection should be reasonable.

select top 10 percent * from [yourtable] order by newid() 

In response to the "pure trash" comment concerning large tables: you could do it like this to improve performance.

select * from [yourtable] where [yourPk] in (select top 10 percent [yourPk] from [yourtable] order by newid()) 

The cost of this will be the key scan of values plus the join cost, which on a large table with a small percentage selection should be reasonable.

added clarification in response to comments
Source Link
Ralph Shillington
  • 21.2k
  • 24
  • 95
  • 156
select top 10 percent * from [yourtable] order by newid() 

In response to the "pure trash" comment concerning large tables you could do it like as a performance alternative.

select * from [yourtable] where [yourPk] in (select top 10 percent [yourPk] from [yourtable] order by newid()) 

The cost of this will the key scan of values plus the join cost, which on a large table with a small percentage selection should be reasonable.

select top 10 percent * from [yourtable] order by newid() 
select top 10 percent * from [yourtable] order by newid() 

In response to the "pure trash" comment concerning large tables you could do it like as a performance alternative.

select * from [yourtable] where [yourPk] in (select top 10 percent [yourPk] from [yourtable] order by newid()) 

The cost of this will the key scan of values plus the join cost, which on a large table with a small percentage selection should be reasonable.

Source Link
Ralph Shillington
  • 21.2k
  • 24
  • 95
  • 156

select top 10 percent * from [yourtable] order by newid()