当前位置:Gxlcms > 数据库问题 > Sql Server 删除表名包含指定字符串的表

Sql Server 删除表名包含指定字符串的表

时间:2021-07-01 10:21:17 帮助过:6人阅读

删除包含指定字符串的表

create procedure sys_DeleteTableByTableName(@bianliang varchar(100))
as
begin
declare @biao varchar(100),@sql varchar(1000)
set @sql=‘%‘+@bianliang+‘%‘
declare c cursor for select name from sysobjects where type=‘u‘ and name like @sql
set @sql=‘drop table ‘
open c
fetch c into @biao
while @@fetch_status=0
begin
     set @sql=@sql+@biao
     exec(@sql)
     set @sql=‘drop table ‘
     fetch c into @biao
end
close c
deallocate c
return
end

 

执行方法:
EXEC  sys_DeleteTableByTableName ‘StuInfo_Backup_2015‘

 

Sql Server 删除表名包含指定字符串的表

标签:

人气教程排行