HEELPBOOK - Drop All Tables in a Database Quickly (SQL Server) ###################### Just a quick and dirty way of dropping all the tables in a database, without dropping the database itself. Useful for when your writing data migration scripts and staging data and need to wipe out your development environment real quick...or, when you've found that uber cool sql-injection-able site and want to wreak some havoc (I don't condone the latter, but I do think its funny from time to time when it happens to the 'big companies'). ######## Code 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; ############ ARTICLE INFO ############# Article Month: December Article Date: 10/12/2012 Permalink: http://heelpbook.altervista.org/2012/drop-all-tables-in-a-database-quickly-sql-server/ Source: http://www.fragmentedcode.com/2008/04/22/sql-server-drop-tables-database-quickly/ Language: English View more articles on: http://www.heelpbook.net/ Follow us on Facebook: http://it-it.facebook.com/pages/HeelpBook/100790870008832 Follow us on Twitter: https://twitter.com/#!/HeelpBook Follow us on RSS Feed: http://feeds.feedburner.com/Heelpbook Follow us on Delicious: http://delicious.com/heelpbook Linkedin: http://it.linkedin.com/pub/stefano-maggi/27/73a/b20 Google+ : https://plus.google.com/116990277568167008289/posts