sql server 同时删除一个数据库所有表名以p开头的表

CREATE PROCEDURE dbo.deletetable
AS
DECLARE @Name as NVARCHAR(128)
DECLARE curObject CURSOR FOR
select   name   from   sysobjects   where   type='U'  and name like 'p%'
OPEN curObject
FETCH NEXT FROM curObject INTO @Name
WHILE(@@FETCH_STATUS=0)
BEGIN
print 'drop table '+@Name
exec('drop table '+@Name)
FETCH NEXT FROM curObject INTO @Name
END
close curObject
deallocate curObject
GO


exec deletetable

你可能感兴趣的:(Database)