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
然后 exec 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
然后 exec sp_drop_tbl