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

SQl SERVER 2000 遍历表中数据的方法

方法一:使用游标
declare @ProductName nvarchar(50)
declare pcurr cursor for select ProductName from Products
open pcurr
fetch next from pcurr into @ProductName
while (@@fetch_status = 0)
begin
print (@ProductName)
fetch next from pcurr into @ProductName
end
close pcurr
deallocate pcurr
此方法适用所有情况,对标结构没有特殊要求。
方法二:使用循环
declare @ProductName nvarchar(50)
declare @ProductID int
select @ProductID=min(ProductID) from Products
while @ProductID is not null
begin
select @ProductName=ProductName from Products where
ProductID=@ProductID
print(@ProductName);
select @ProductID=min(ProductID) from Products where
ProductID>@ProductID
end
此方法适用于表带有自动增加标识的字段


相关文档:

oracle sql优化之多表连接优化


Use equality first.
使用等连接
Use range operators only where equality does not apply.
只有在等连接不可用的情况下事由区间连接
Avoid use of negatives in the form of !=
or NOT.
避免使用 != 或者 not
Avoid LIKE pattern matching.
避免使用 LIKE匹配
Try to retrieve specific rows and in small n ......

重新编译所有无效的PL/SQL模块(对象)

当Oracle数据库创建完成后,系统将会自动运行utlrp.sql这个脚本文件(D:\oracle\product\10.1.0\Db_1\RDBMS\ADMIN),但是,当通过定制安装类型的方式创建了数据库时,系统则不会运行utlrp.sql这个脚本,所以,建议在创建、更新或迁移一个数据库后,运行一下utlrp.sql这个脚本,以验证数据库安装是否成功,这样可以重新编译 ......

实验五 SQL查询(排序、集函数和分组子句的应用)

试验目的:
一、学习查询结果的排序
二、学习使用集函数的方法,完成统计
等查询。
三、学习使用分组子句
一、学习查询结果的排序
1、查询全体学生信息,结果按照年龄降
序排序
select *
from student
order by sage desc
2、查询学生选修情况,结果先按照课程
号升序排序,再按成绩降序排序
select *
from ......

SQL分页查询

/*第几页必须大于1
select top 每页数量 * id
 from @t a
 where id not in
 (select top (第几页-1)*每页数量 id
  from @t b
 )
*/
declare @lcSqlCommand nvarchar(100)
declare @t table (id int IDENTITY,orderDate datetime)
insert into @t
 select orderDate
&nb ......

sql语句基础

--sql structured query language
--DML--Data Manipulation Language--数据操作语言
query information (SELECT),
add new rows (INSERT),
modify existing rows (UPDATE),
delete existing rows (DELETE),
perform a conditional update or insert operation (MERGE),
see an execution plan of SQL (EXPLA ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号