如:删掉12结尾的表declare cursor1 cursor for select name from sysobjects where xtype='u' and name like '%12'
declare @i varchar(1000)
open cursor1
fetch cursor1 into @i
while @@fetch_status=0
begin
exec('drop table '+@i)
fetch cursor1 into @i
end
close cursor1
deallocate cursor1
declare @i varchar(1000)
open cursor1
fetch cursor1 into @i
while @@fetch_status=0
begin
exec('drop table '+@i)
fetch cursor1 into @i
end
close cursor1
deallocate cursor1
create table twoTable(id varchar(5))
create table threeTable(id char(5))if exists(select name from sysobjects where name='delTable' and xtype='FN')
drop function delTable
gocreate function delTable(@n varchar(20)
return int
as
begin
declare @v int
exec('drop table '+@n)
if @@error <> 0
@v = 0
else
@v = 1
return @v
end
goselect name into #tmp from sysobjects where xtype='u' and name like '%le'
select delTable(name) from #tmp