游标的例子

来源:互联网 发布:云计算基础架构平台 编辑:程序博客网 时间:2024/05/12 20:36

--游标的例子(删除包含'T'字母的表)
declare @sql varchar(200),@table varchar(200)
declare fetch_id cursor for Select name From sysobjects Where OBJECTPROPERTY(id,'IsUserTable')=1 and name like '%t%'
open fetch_id
fetch fetch_id into @table
while @@fetch_status=0
begin
 set @sql='drop table '+@table
 Exec master..xp_cmdshell @sql,No_Output
 fetch next from fetch_id into @table
end
close fetch_id
deallocate fetch_id

 

原创粉丝点击