用游标删除清空数据库

来源:互联网 发布:windows managenent 编辑:程序博客网 时间:2024/05/22 11:41

declare @sql nvarchar(500)

declare @Name nvarchar(200)

set @sql=''

set @Name =''

Declare Cur Cursor For select name from sysobjects where xtype='u' and name like 'Form_%'

Open Cur 

Fetch next From Cur Into @Name 

set @sql=''

While @@fetch_status=0 

Begin 

set @sql = 'delete from '+@Name

print @sql

exec(@sql)

Fetch Next From Cur Into @Name 

End 

Close Cur 

Deallocate Cur