删除数据库中所有表的记录,怎么不工作?

use emsb7_test1023 

declare   @name varchar(140

declare  ##cursor cursor for select name from   emsb7_test1023.dbo.sysobjects where xtype='U' 

open ##cursor
fetch next from ##cursor into @name 

while   @@fetch_status=0   

begin   
exec('truncate table '+ @name
  ----少些一句:fetch next from ##cursor into @name 从而陷入了死循环
end 

close ##cursor   

deallocate ##cursor 
怎么不工作? 原因就是
----少些一句:fetch next from ##cursor into @name 从而陷入了死循环


use emsb7_test1023 

declare   @name varchar(140

declare c cursor for select name from   emsb7_test1023.dbo.sysobjects where xtype='U' 

open c
fetch next from c into @name 

while   @@fetch_status=0   

begin   
exec('truncate table '+ @name
fetch next from c into @name 
end 

close c   

deallocate c

posted on 2008-05-08 10:51  simhare  阅读(309)  评论(0)    收藏  举报

导航