现在的位置: 首页 > 综合 > 正文

数据库中游标的使用…..用于循环

2012年09月25日 ⁄ 综合 ⁄ 共 439字 ⁄ 字号 评论关闭
 1declare @temp varchar(150)
 2declare @sql varchar(128)
 3
 4declare aa cursor for              //声明游标
 5  select  name from sysobjects where type = 'u'order by refdate desc        //游标所执行的语句
 6open aa                     打开游标
 7fetch next from aa into @temp   //进行循环
 8while(@@fetch_status=0)          //执行成功为0
 9begin
10   set @sql = 'delete from [' + @temp + ']'
11   execute(@sql)
12   fetch next from aa into @temp
13end
14close aa
15deallocate aa

抱歉!评论已关闭.