sqlserver分页
现在一般常用的有以下2种方法:
1. select top @pagesize * from table1 where id not in (select top @pagesize*(@page-1) id from table1 order by id) order by id
2. select * from (select top @pagesize * from (select top @pagesize*@page * from table1 order by id) a order by id desc) b order by id
相关文档:
SQLServer2005通过intersect,union,except和三个关键字对应交、并、差三种集合运算。
他们的对应关系可以参考下面图示
相关测试实例如下:
use tempdb
go
if (object_id ('t1' ) is not null ) drop table t1
if (object_id ('t2' ) is not null ) drop table t2
go ......
--每个月的第一天
select dateadd(dd,-datepart(dd,getdate())+1,getdate())
--第个月的最后一天
select dateadd(dd,-datepart(dd,getdate()),dateadd(mm,1,getdate()))
--本月的天数
select datediff(dd,getdate(),dateadd(mm,1,getdate()))
......
一、SQLServer 通用索引字段
1、Primary Key's 主键
2、Foreign Key's 外键
3、支持SELECT、INSERT、UPDATE和DELETE命令的字段 :
(1)、INNER JOIN
(2)、RIGHT | LEFT OUTER JOIN
(3)、WHERE
(4)、ORDER BY
(5)、GROUP BY
(6)、HAVING
二、创建索引的其他因素(主要因素都因为索引是数据表外部 ......
1、查看原数据库备份情况:RESTORE FILELISTONLY from DISK = 'c:\NMGCNC-BABY_2009-4-1.dat' WITH NOUNLOAD, FILE = 1
2、进行数据库还原:
restore database babyAndwed from DISK = 'c:\NMGCNC-BABY_2009-4-1.dat' with move 'babyAndwed_Data' to
'c:\NMGCNC-BABY_Data.MDF',move 'babyAndwed_Log' to 'c:\NMGCNC-B ......
原文出处:http://www.cnblogs.com/luoht/archive/2010/03/01/1676049.html
用IN写出来的SQL的优点是比较容易写及清晰易懂,这比较适合现代软件开发的风格。
但是用IN的SQL性能总是比较低的,从SQL执行的步骤来分析用IN的SQL与不用IN的SQL有以下区别:
SQL试图将其转换成多个表的连接,如果转换不成功则先执行 ......