易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

触发器获取修改表的SQL语句


/*
触发器获取SQL语句增量传输
功能:捕捉修改表的SQL语句
使用说明: 1、先新建一表手动写入主键信息或者唯一索引
   Create table prmary_key
   (tab_name varchar(255),
    key_name varchar(255))
   --此表仅在建立触发器时使用,建完所有触发器后 记得 ......

高级SQL @Oracle

1.集合操作
学习oracle
中集合操作的有关语句,
掌握union,union
all,minus,interest的使用,能够描述结合运算,并且能够将多个查询组合到一个查询中去,能够控制行返回的顺序。
包含集合运算的
查询称为复合查询。见表格1-1
表1-1
Operator         Returns     &nb ......

总结经典常用的SQL语句(2)

向表中添加一个新记录,你要使用SQL INSERT 语句。
这里有一个如何使用这种语句的例子:
INSERT mytable (mycolumn) VALUES (‘some data’)
这个语句把字符串’some data’插入表mytable的mycolumn字段中。将要被插入数据的字段的名字在第一个括号中指定,实际的数据在第二个括号中给出。
I ......

SQL Server中存储过程与函数的区别

SQL Server用户自定义函数和存储过程有类似的功能,都可以创建捆绑SQL语句,存储在server中供以后使用。这样能够极大地提高工作效率,通过以下的各种做法可以减少编程所需的时间:
   1 重复使用编程代码,减少编程开发时间。
   2 隐藏SQL细节,把SQL繁琐的工作留给数据库开发人员,而程序开发员则集中处理高级编程 ......

ms sql到mysql的移植:关于数据类型移植的一些问题

   ms sql中的int型默认是4位,mysql的int型默认是11位,前者到后者的移植不会有什么隐患,但是后者到前者的移植就存在位数不够,不能存储大数的隐患。
   还有bigint,ms sql是8位,mysql默认是20位。 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号