日期:2014-05-18  浏览次数:20497 次

100万条数据的表如何快速随机抽取10条数据
select top 10 * from tablename order by newid()
这个速度太慢了,要等半分钟。有没有快速点的办法。

表的主键是varchar类型的,主键是字符串而不是int

------解决方案--------------------
SQL code
set nocount on--75151448行数据
select count(*) from syscolumns a,syscolumns b,syscolumns c 

set statistics time on 

select
 top 10 * from(select a.name as name,left(b.name,10) as name1, checksum(newid()) as hash    from syscolumns a,syscolumns b,syscolumns c )t 
where
 hash%100=0

set statistics time off

set nocount off