三种SQL分页法
三种SQL分页法
表中主键必须为标识列,[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
SELECT TOP 页大小 *
from TestTable
WHERE (ID NOT IN
(SELECT TOP (页大小*(页数-1)) id
from 表
ORDER BY id))
ORDER BY ID
2.分页方案二:(利用ID大于多少和SELECT TOP分页)
语句形式:
SELECT TOP 10 *
from TestTable
WHERE (ID >=
(SELECT MAX(id)
from (SELECT TOP 21 id
from TestTable
ORDER BY id) AS T))
ORDER BY ID
SELECT TOP 页大小 *
from TestTable
WHERE (ID >=
(SELECT MAX(id)
from (SELECT TOP (页大小*(页数-1)+1) id
from 表
ORDER BY id) AS T))
ORDER BY ID
3.分页方案三:(利用SQL的游标存储过程分页)
create procedure SqlPager
@sqlstr nvarchar(4000), --查询字符串
@currentpage int, --第N页
@pagesize int --每页行数
as
set nocount on
declare @P1 int, --P1是游标的id
@rowcount int
exec sp_cursoropen @P1 output,@sqlstr,@scrollopt=1,@ccopt=1, @rowcount=@rowcount
相关文档:
(1) 选择最有效率的表名顺序(只在基于规则的优化
器中有效):
Oracle
的
解析器按照从右到左的顺序处理from子句中的表名,from子句中写在最后的表(基础表 driving
table)将被最先处理,在from子句中包含多个表的情况下,你必须选择记录条数最少的表作为基础表。假如有3个以上的表连接查询,
那就 ......
1 防止sql注入式攻击(可用于UI层控制) #region 防止sql注入式攻击(可用于UI层控制)
2
3 /**/ ///
4 /// 判断字符串中是否有SQL攻击代码
5 ///
6 /// 传入用户提交数据
7 /// ......
SQL Lite
SQLite is a small C library that implements a self-contained, embeddable, zero-configuration SQL database engine.
It is a open source product and can be downloaded from http://www.sqlite.org/ . SQL Lite is best suited in Smart Client architecture, where we can locally store all ......
SQL注入是目前比较常见的针对数据库的一种攻击方式。在这种攻击方式中,攻击者会将一些恶意代码插入到字符串中。然后会通过各种手段将该字符串传递到SQLServer数据库的实例中进行分析和执行。只要这个恶意代码符合SQL语句的规则,则在代码编译与执行的时候,就不会被系统所发现。由此可见SQL注入式攻击的危害是很大的,那么 ......
基于msdn 详细学习T-SQL (http://msdn.microsoft.com/zh-cn/library/bb510741.aspx)
2. 今天下午没什么run 分析。。。 对照着msdn 简单教程,乘机把基本的T-SQL 语句操作一遍(http://msdn.microsoft.com/zh-cn/library/ms365303.aspx)
Use master
Go
Create database dbname On&n ......