sql server 批量删除数据表

时间:2022-03-05 02:44:56

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
alter PROCEDURE [dbo].[CANCELTABLE]

AS
BEGIN
DECLARE @cul int
declare @tablename varchar(50)
declare @dropSql nvarchar(100)
select @cul=COUNT(name) from sysobjects where name like 'stt%'
while @cul>0
begin

select @tablename=tb1.name from (select top 1 name from sysobjects where name like 'stt%') as tb1
set @dropSql='drop table'+' '+@tablename;
EXECUTE sp_executesql @dropSql
select @cul=COUNT(name) from sysobjects where name like 'stt%'
end

END
GO