simhare

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

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

分类:

技术点:

相关文章: