Here is the quick and dirty, using the undocumented sp_MSForEachTable:
USE YourDatabase
EXEC
sp_MSForEachTable @command1 =
"DROP TABLE ?"
--DROP ALL TABLES
USE YourDatabaseName
GO
DECLARE @TableName VARCHAR(150)
DECLARE @SQL VARCHAR(300)
SELECT @TableName = (
SELECT TOP 1 [name]
FROM sys.objects
WHERE [type] = 'U'
ORDER BY [name] )
WHILE @TableName IS NOT NULL
BEGIN
SELECT @SQL = 'DROP TABLE [dbo].[' + RTRIM(@TableName) +']'
EXEC (@SQL)
PRINT 'Dropped Table : ' + @TableName
SELECT @TableName = (
SELECT TOP 1 [name]
FROM sys.objects
WHERE [type] = 'U'
AND [name] > @TableName
ORDER BY [name] )
END
No comments:
Post a Comment