易截截图软件、单文件、免安装、纯绿色、仅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语句案例—分析函数的使用

创建雇员表:
create table emp(deptno number(10),ename varchar2(100),sal number(10,2));
插入数据
begin
insert into emp values('10','KING',5000);
insert into emp values('10','CLARK',2450);
insert into emp values('10','MILLER',1300);
insert into emp values('20','SCOTT',3000);
insert into emp v ......

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

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

sql索引类型

索引类型
唯一索引:唯一索引不允许两行具有相同的索引值
主键索引:为表定义一个主键将自动创建主键索引,主键索引是唯一索引的特殊类型。主键索引要求主键中的每个值是唯一的,并且不能为空
聚集索引(Clustered):表中各行的物理顺序与键值的逻辑(索引)顺序相同,每个表只能有一个
非聚集索引(Non-clustered):非聚 ......

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号