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 课件,便随手下载了下来看看主要讲了些什么内容,于是看到了下面两个PPT页面
由于第一张PPT上的内容不太准确(日志文件中没有“日志页”的概念,只有VLF的概念,可能是我们对“数据页”的概念太深刻了,因此弄了以&ldq ......
''' <summary>
''' SQL文執行結果のEXCEL出力
''' </summary>
''' <param name="connString">OLEDB接続文字列</param>
''' <param name="sqlString">SQL文</param>
''' <param name="savePath">出力ファイルパス</param>
......
假设你想找书中的某一个句子。你可以一页一页地逐页搜索,但这会花很多时间。而通过使用索引,你可以很快地找到你要搜索的主题。
表的索引与附在一本书后面的索引非常相似。它可以极大地提高查询的速度。对一个较大的表来说,通过加索引,一个通常要花费几个小时来完成的查询只要几分钟就可以完成。因此没有理由对 ......
--desc 表名 描述表的内容
desc emp;
--加上数学表达式和列名 ""保持格式
select ename "name space", sal*12 year_sal from emp;
select 2*3 from dual;
select sysdate from dual;
--空值的数学表达式 结果都是空值
select ename, sal*12 + comm from emp;
- ......
注'svw'为出问题的数据库,此方式对sql7.0以上版本有效,其它低版本为测试
sp_configure 'allow',1
go
reconfigure with override
go
update sysdatabases set status=32768 where name='svw'
go
dbcc rebuild_log('svw','D:\mssql7\data ......