Delete or Truncate All Data in a Database

A quick tip for you all, ever need to delete or truncate all the data from a database? There has been a few times during testing after my database grew, that I needed a quick solution to clear a database. The solution is using the MSForEachTable stored procedure. Simply do the following :

DatabaseName – The name of the database you need to clear out.

To Delete :

USE DatabaseName
EXEC sp_MSForEachTable 'DELETE FROM ?'

To Truncate :

USE DatabaseName
EXEC sp_MSForEachTable 'TRUNCATE TABLE ?'

Happy Coding!

Jacob Saylor

Software developer in Kentucky

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: