读书人

100万条数据的表怎么快速随机抽取10条

发布时间: 2012-05-04 12:36:09 作者: rapoo

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=0set statistics time offset nocount off 

读书人网 >SQL Server

热点推荐