首页 > 数据库技术 > 详细

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

时间:2014-10-25 23:01:05      阅读:389      评论:0      收藏:0      [点我收藏+]

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表

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!