1.在此表中加入一个recordid项,为[int] IDENTITY (1, 1) NOT NULL
2。利用随即函数,在1到count(*)之间产生随机整数
3。select * from table where recordid = 随机整数
4.计数加一,在一个int数组中保留随机整数。
5。是否到了n个。
6。若没有,利用随即函数,在1到count(*)之间产生下一个随机整数
7。此随机整数是否取过。
8。若有,放弃回到6。
9。若没有,select * from table where recordid = 随机整数
10。回到4。
11。到了n个。结束
2。利用随即函数,在1到count(*)之间产生随机整数
3。select * from table where recordid = 随机整数
4.计数加一,在一个int数组中保留随机整数。
5。是否到了n个。
6。若没有,利用随即函数,在1到count(*)之间产生下一个随机整数
7。此随机整数是否取过。
8。若有,放弃回到6。
9。若没有,select * from table where recordid = 随机整数
10。回到4。
11。到了n个。结束
2。利用随机函数,产生从1到count(*)的随机整数。
3。select * from table where recordid = 随机整数
4。记录个数加1,并将此随机整数保存到一个int数组中
5。记录是否为n了
6。若不是,利用随机函数,产生下一个从1到count(*)的随机整数
7。此数是否用过。
8。若用过,放弃,回到6
9。若没用过,回到3
10。记录到了n个,结束
select top n * from tablename order by NEWID()
select * from #a
drop #a
大家怎么能忘了newid()呢。