存档
以下存储过程能够自动批量删除数据库库内的所有用户表。
可以修改存储过程内的条件来删除指定的表。
删除表时请谨慎!
CREATE PROCEDURE sp_drop_tbl
AS
BEGIN
DECLARE @tblname varchar(80)
DECLARE @dropsql varchar(100)
DECLARE cur1 CURSOR FOR
SELECT name FROM dbo.sysobjects WHERE type = 'U'
OPEN cur1
FETCH cur1 INTO @tblname
WHILE (@@SQLSTATUS = 0)
BEGIN
SELECT @dropsql = "DROP TABLE " + @tblname
EXEC (@dropsql)
FETCH cur1 INTO @tblname
END
CLOSE cur1
DEALLOCATE cursor cur1
END