码迷,mamicode.com
首页 > 数据库 > 详细

一个简单的游标删除SQL SERVER表

时间:2014-10-25 23:02:38      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:sql server cursor

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表

标签:sql server cursor

原文地址:http://blog.csdn.net/waterxcfg304/article/details/40457957

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!