truncate a database(help required urgent)

  • can any body please tell me how to truncate a database???? please help me its very urgent

  • Truncate a table, or truncate the transaction log?  There's information about both of these in Books Online.

    John

  • You cannot truncate a database. What are you trying to accomplish?

    You can drop all tables or truncate all tables but not truncate database.

    Cheers,CrispinI can't die, there are too many people who still have to meet me!It's not a bug, SQL just misunderstood me!

  • yes i want to truncate all the tables in the database can you please tell me the syntax for that

     

    pavan

  • Two ways come to mind immediately. The first would be to script out the database and re-run the script. The second would be to use the sp_MSforeachtable to delete all the records from each table, but that could have some severe consequences for your transaction log. Running the script would have no log consequences.

    This would do the trick:

    sp_MSforeachtable @command1="delete ?"

    You might also have some foreign key issues with this, that might be cleared by running the command twice: the first takes care of the child records, the second the parent records.

    -----
    [font="Arial"]Knowledge is of two kinds. We know a subject ourselves or we know where we can find information upon it. --Samuel Johnson[/font]

  • Can't be done easily if you have foreign keys all over the place.

     

    One thing you can do is script the whole database, rename the actual DB, then run the script to generate a brand new DB.

     

    Other than that you can always run a delete on every table (will throw errors).  But after enough times running this whole script, the DB will be empty.

     

    This is not pretty, but it works... eventually!

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply