DECLARE c2 cursor for
select 'drop table ['+name +']; '
from sysobjects
where xtype = 'u' and name not like 'TRT_%'
open c2
declare @c2 varchar(8000)
fetch next from c2 into @c2
while(@@fetch_status=0)
begin
exec(@c2)
fetch next from c2 into @c2
end
close c2
select 'drop table ['+name +']; '
from sysobjects
where xtype = 'u' and name not like 'TRT_%'
open c2
declare @c2 varchar(8000)
fetch next from c2 into @c2
while(@@fetch_status=0)
begin
exec(@c2)
fetch next from c2 into @c2
end
close c2
本文提供了一个使用T-SQL声明游标并批量执行删除操作的例子,该脚本从不含TRT_前缀的所有表中删除数据。
1386

被折叠的 条评论
为什么被折叠?



