DELETE all tables in a Database (MS SQL)

Filed Under (SQL) by admin on 31-03-2009

SELECT name INTO #tables from sys.objects where type = 'U'

while (SELECT count(1) FROM #tables) > 0

begin

declare @sql varchar(max)

declare @tbl varchar(255)

SELECT top 1 @tbl = name FROM #tables

SET @sql = 'drop table ' + @tbl

exec(@sql)

DELETE FROM #tables where name = @tbl

end

DROP TABLE #tables