select top 10 * from tablename order by newid()
这个速度太慢了,要等半分钟。有没有快速点的办法。表的主键是varchar类型的,主键是字符串而不是int

解决方案 »

  1.   

    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
      

  2.   

    数据量太大,每次都order by newid()效率上确实会有问题。
      

  3.   

    --try
    select top 10 *
    from tablename tablesample(1000 rows)
    order by newid()
      

  4.   

    直接 top 10 ,不用order by 应该最快了 
      

  5.   


    这个是什么意思啊?看不懂,太深奥了,
    我的比如表名是 T1列名是C1,要怎么写sql语句