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
此方法适用于表带有自动增加标识的字段
相关文档:
如果你经常遇到下面的问题,你就要考虑使用SQL Server的模板来写规范的SQL语句了:
SQL初学者。
经常忘记常用的DML或是DDL SQL 语句。
在多人开发维护的SQL中,每个人都有自己的SQL习惯,没有一套统一的规范。
在SQL Server Management Studio中,已经给大家提供了很多常用的现成SQL规范模板。
SQL Server Management ......
当Oracle数据库创建完成后,系统将会自动运行utlrp.sql这个脚本文件(D:\oracle\product\10.1.0\Db_1\RDBMS\ADMIN),但是,当通过定制安装类型的方式创建了数据库时,系统则不会运行utlrp.sql这个脚本,所以,建议在创建、更新或迁移一个数据库后,运行一下utlrp.sql这个脚本,以验证数据库安装是否成功,这样可以重新编译 ......
这个函数DateAdd(month,2,WriteTime):
日期部分缩写 Year yy, yyyy quarter qq, q Month mm, m dayofyear dy, y Day dd, d Week wk, ww Hour hh minute mi, n second ss, s millisecond ms
这个表足够说明问题了吧,从year到millisecond都可以处理,够方便了吧.
DATEDIFF 函数 [日期和时间]
-------------- ......
这两天都没有好好学习,今天终于算投入了些,由于课程的关系,我的sql也是同vb一起学习的。虽然知道贪多嚼不烂,可是按照实际情况,我完全没有理由抛弃sql的。
最近都把时间投入到vb和面向对象中,sql今天好好复习了下,从create database 开始,create table,alter table , add constraint …&h ......