Delete all datas in the database

Posted on 2007-10-15
Last Modified: 2010-03-19
Hi Experts,

I need to delete all the datas in my database.
I want to select all the tables (except the system tables), then delete all the datas in those tables to clear the database.

Thanks in advance for your help.
Question by:noulouk
    LVL 75

    Assisted Solution

    by:Aneesh Retnakaran
    the best option will be to create a new database by generating the DB script and after that you can delete the original db and rename the new one back to the original
    LVL 142

    Accepted Solution

    please check out this script:

    EXEC sp_MSForEachTable 'TRUNCATE TABLE ?'
    LVL 10

    Expert Comment

              I learnt something new today. :)
    Thanks man

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    MS SQL - Output to columns equally. 5 42
    How to format datetime as mm/dd/yyyy 6 56
    SQL Question 1 26
    combine data in sql 1 23
    I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
    In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
    This video discusses moving either the default database or any database to a new volume.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now