SQL 取n到m条记录
1.
select top m * from tablename where id not in (select top n id from tablename)
2.
select top m * into 临时表(或表变量) from tablename order by columnname -- 将top m笔插入
set rowcount n
select * from 表变量 order by columnname desc
3.
select top n * from
(select top m * from tablename order by columnname) a
order by columnname desc
4.如果tablename里没有其他identity列,那么:
select identity(int) id0,* into #temp from tablename
取n到m条的语句为:
select * from #temp where id0 >=n and id0 <= m
如果你在执行select identity(int) id0,* into #temp from tablename这条语句的时候报错,那是因为你的DB中间的select into/bulkcopy属性没有打开要先执行:
exec sp_dboption 你的DB名字, "select into/bulkcopy ",true
5.如果表里有identity属性,那么简单:
select * from tablename where identitycol between n and m
比如一个表有100条记录怎么取其中的第30至第40条记录??
select &nbs
相关文档:
Introduction
Microsoft SQL Server 2008 R2 is the latest release of SQL Server. This article will introduce the top 10 features and benefits of SQL Server 2008 R2. The “R2” tag indicates this is an intermediate release of SQL Server and not a major revision. However, there are a number o ......
SQL Server用户自定义函数和存储过程有类似的功能,都可以创建捆绑SQL语句,存储在server中供以后使用。这样能够极大地提高工作效率,通过以下的各种做法可以减少编程所需的时间:
1 重复使用编程代码,减少编程开发时间。
2 隐藏SQL细节,把SQL繁琐的工作留给数据库开发人员,而程序开发员则集中处理高级编程 ......
ms sql中的int型默认是4位,mysql的int型默认是11位,前者到后者的移植不会有什么隐患,但是后者到前者的移植就存在位数不够,不能存储大数的隐患。
还有bigint,ms sql是8位,mysql默认是20位。 ......
查询通知是在 Microsoft SQL Server 2005 中以及 ADO.NET 2.0 的 System.Data.SqlClient 命名空间中引入的。查询通知建立在 Service Broker 基础结构的基础上,使应用程序可以在数据更改时收到通知。如果应用程序提供数据库中信息的缓存(例如 Web 应用程序),需要在源数据更改时接收通知,此功能特别有用。
通过三种方式 ......
1使用不带参数的存储过程
使用 JDBC 驱动程序调用不带参数的存储过程时,必须使用 call SQL 转义序列。不带参数的 call 转义序列的语法如下所示:
以下是引用片段:
{call procedure-name}
作为实例,在 SQL Server 2005 AdventureWorks 示例数据库中创建以下存储过程:
以下是引用片段:
......