标签:top strong new row nbsp alt ble and span
方法1:最普通的写法,性能慢
SELECT top 10 ID,name FROM dt_keyword ORDER BY NEWID()
方法2:性能还可以
//先给数据库增加一列
ALTER TABLE dt_keyword ADD SortKey AS NEWID()
//查询时执行下边sql SELECT top 10 ID,name FROM dt_keyword WHERE SortKey LIKE ‘A%B%C%D%E%F%‘
方法3:效率还好,含sql2008以上支持
SELECT TOP 10 * FROM dt_keyword tablesample (10000 Rows)
方法4:如果id连续,速度最快
SELECT top 10 * FROM dt_keyword where id>=(select count(ID) from dt_keyword)*rand()
方法5:如果id不连续,速度最快
SELECT top 10 * FROM dt_keyword
where id>=(select max(ID) from dt_keyword)*rand()
//如果您有更好的方法请留言
标签:top strong new row nbsp alt ble and span
原文地址:https://www.cnblogs.com/webapi/p/10184583.html