Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2006
    Posts
    38

    Unanswered: How to cleanup all database?

    hello,if I want to cleanup all the data that in a database,how to do?
    thanks!

  2. #2
    Join Date
    Jun 2003
    Posts
    269
    run this query and execute the result.it will clean ur DB.
    Note:It does not deal with foreign constraints but when using brute force, running it a few times should deal.
    Code:
    select 'truncate table ['+o.name+']' 
    from sysobjects o
    where o.xtype='U'
    and o.name <>'dtproperties'
    Last edited by mallier; 03-06-06 at 07:54.
    I love cursor,though I never use it.Cos' I dont want to misuse it.
    ----------------------------------------------

    ----cheers
    ----http://mallier.blogspot.com

  3. #3
    Join Date
    Dec 2004
    Location
    Kharkov, Ukraine
    Posts
    40
    sp_MSforeachtable 'delete from ?'
    This is simpler

  4. #4
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    I prefer "drop database ..." It cleans up all those pesky files that SQL Server never really needed anyway.

  5. #5
    Join Date
    Feb 2006
    Posts
    38
    Quote Originally Posted by mwolf
    sp_MSforeachtable 'delete from ?'
    This is simpler
    it means I have to run this query many times!
    I want to cleanup my database in one times

  6. #6
    Join Date
    Jul 2002
    Posts
    229
    You could generate scripts for dropping and re-creating all table objects (+concerned indexes, keys, constraints etc)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •