select top 10 * from 表 order by newid()

解决方案 »

  1.   

    declare @maxnum integer,@li_x integer,@li_y integer
    select @maxnum = count(*) from table 
    create table #temptable1 (xh integer null,randnum integer null)select @li_y = 1
    while @li_y <= @maxnum + 1
      begin
        while exists(select randnum from #temptable1 where randnum = @li_x)
          begin
            select @li_x = rand(datepart(ss,getdate()) * @maxnum + 1
          end
        insert #temptable1 (xh,randnum) values (@li_y,@li_x)
        select @li_y = @li_y + 1
      endselect identity(1,1) as xh,col1,col2,... into #temptable2 from tablename
    select top 10 #temptable2.* from #temptable2,#temptemp1 
      where #temptable2.xh = #temptable1.xh 
      order by #temptable1.randnumdrop table #temptable1
    drop table #temptable2