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
此方法适用于表带有自动增加标识的字段
相关文档:
http://www.umgr.com/blog/PostView.aspx?bpId=36294
1. 执行sql语句
int sqlite3_exec(sqlite3*, const char *sql, sqlite3_callbacksql 语法
, void *, char **errmsg );
这就是执行一条 sql 语句的函数。
第1个参数不再说了,是前面open函数得到的指针。说了是关键数据结构。
第2个参数const char ......
文本 nvarchar(n)
备注 ntext
数字(长整型) int
数字(整型) smallint
数字(单精度) real
数字(双精度) float
数字(字节) tinyint
货币 money
日期 smalldatetime
布尔 bit
附:转换成SQL的脚本。
ALTER TABLE tb ALTER COLUMN aa Byte 数字[字节]
ALTER TABLE tb ALTER COLUMN aa Long 数字[长整型]
ALTER T ......
试验目的:
一、学习查询结果的排序
二、学习使用集函数的方法,完成统计
等查询。
三、学习使用分组子句
一、学习查询结果的排序
1、查询全体学生信息,结果按照年龄降
序排序
select *
from student
order by sage desc
2、查询学生选修情况,结果先按照课程
号升序排序,再按成绩降序排序
select *
from ......
索引类型
唯一索引:唯一索引不允许两行具有相同的索引值
主键索引:为表定义一个主键将自动创建主键索引,主键索引是唯一索引的特殊类型。主键索引要求主键中的每个值是唯一的,并且不能为空
聚集索引(Clustered):表中各行的物理顺序与键值的逻辑(索引)顺序相同,每个表只能有一个
非聚集索引(Non-clustered):非聚 ......
在PL/SQL中也提供GOTO语句,其语法是
GOTO label;
这里label是在PL/SQL块中定义的标签.标签是用双箭头括号括起来的.当执行GOTO语句的时候,控制会立即转到由标签标识的语句.
1.对于GOTO的限制
a.对于块,循环或者IF语句而言,想要从外层跳到内层是非法的.
b.使用GOTO子句从一个IF子句跳到另一个子句中也是非法的.
begin
......