标签:style os ar sp strong div on bs ad
一、前5条随机记录
SELECT top 5 * FROM Orders ORDER BY NEWID()
二、生成随机数
select rand(100) from orders
三、删除重复的记录
sql="delete from dv_user where userlastip in (select userlastip from dv_user group by userlastip having (count(*))>1)"
四、三种分页效率分析
表中主键必须为标识列,[ID] int IDENTITY (1,1)
1.分页方案一:(利用Not In和SELECT TOP分页)
SELECT TOP 10 * FROM TestTable
WHERE (Id NOT IN (SELECT TOP 20 id FROM TestTable
ORDER BY id ))
ORDER BY ID
语句形式:利用Not In和SELECT TOP分页) 效率中,需要拼接SQL语句
2.分页方案二:(利用ID大于多少和SELECT TOP分页)
语句形式:利用ID大于多少和SELECT TOP分页)效率最高,需要拼接SQL语句
SELECT TOP 10 * FROM TestTable (SELECT TOP 20 id FROM TestTable ORDER BY id) AST) ) |
3.分页方案三:(利用SQL的游标存储过程分页)
语句形式:利用SQL的游标存储过程分页) 效率最差,但是最为通用
create procedure SqlPager |
标签:style os ar sp strong div on bs ad
原文地址:http://www.cnblogs.com/q994321263/p/4065587.html