首页 > 代码库 > 一个简单的游标删除SQL SERVER表
一个简单的游标删除SQL SERVER表
use databaseName
declare @tblname char(100)
declare @sql char(5000)
declare table_cursor cursor for select name from sysobjects where name like ‘tb_card[_]%‘ and name<>‘Tb_card_regist‘ and name<>‘Tb_card_item‘ and name<>‘Tb_card_discrule‘ and name<>‘tb_card_packagesetdetail‘ and name<>‘tb_card_packagedetail‘ and name<>‘tb_card_exchangeitem‘
and name<>‘tb_card_package‘
open table_cursor
fetch next from table_cursor into @tblname
WHILE @@FETCH_STATUS = 0
BEGIN
set @sql=‘delete from ‘+@tblname
exec(@sql)
print ‘delete ‘ +@tblname + ‘successful‘
fetch next from table_cursor into @tblname
END
close table_cursor
deallocate table_cursor
一个简单的游标删除SQL SERVER表
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。