本人收集的,挺有用的 1. 利用游标循环更新.删除MemberAccount表中的数据 DECLARE My_Cursor CURSOR --定义游标 FOR (SELECT * FROM dbo.MemberAccount) --查出需要的集合放到游标中 OPEN My_Cursor; --打开游标 FETCH NEXT FROM My_Cursor ; --读取第一行数据 WHILE @@FETCH_STATUS = 0 BEGIN --UPDATE dbo.MemberAccount SE
[cursor]游标:用于循环表行数据,类似指针 格式如下: declare tempIndex cursor for (select * from table) --定义游标 open tempIndex --打开游标 fetch next from tempIndex into @x --抓取下一行数据给变量 --0表示抓取成功,1表示抓取失败,2表示不存在抓取行 begin --sql 语句 end close tempIndex --关闭游标 deallocate tempIndex -
原文:SQL Server 游标运用:查看所有数据库所有表大小信息(Sizes of All Tables in All Database) 一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 实现代码(SQL Codes) 方法一:游标 + 系统存储过程sp_MSForEachDB 方法二:封装sp_MSforeachtable + sys.databases 方法三:系统存储过程sp_MSForEachDB + sp_MSforeacht
原文:SQL Server 游标运用:查看一个数据库所有表大小信息(Sizes of All Tables in a Database) 一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 实现代码(SQL Codes) 方法一:运用游标 方法二:运用系统存储过程 方法三:拼接SQL 参考文献(References) 二.背景(Contexts) 在性能调优或者需要了解某数据库表信息的时候,最直观的方式就是罗列出这个数据所有表的信息,这些信息
sql server游标: --定义游标 declare cursor1 cursor for select ID,Name from A --打开游标 open cursor1 declare @id int declare @name varchar(50) declare @n int declare @i int=1 set @n=(select COUNT(1) from A) while(@i<@n) begin set @i=@i+1 fetch next from cursor1