Search code examples
c#.netsql-server-cesql-server-ce-3.5

Delete all data from all tables


Is there an elegant way to wipe all data in the database (removing every row from every table) without destroying the architecture and having to remove/read constraints?

I could just delete data from each table but this seems tedious. I've seen plenty of solutions for full on SQL implementations that make use of a stored procedure but obviously that functionality is not available to me. It's likely I won't be making this function available to end users of the product but it may be enabled for in-house testing purposes. As I stated I can do this manually so put this one down to curiosity


Solution

  • No. Since you want the db structure to remain intact including all relationships. Hence, first delete all master data and then slave data.

    your script should contain truncate queries in a specific order.

    Otherwise what you can do is generate a entire db schema and keep it at your disposal. wheneever you need to empty the db, drop the db, recreate it :)

    on how to generate schema for SQL-CE db..use SQLCE-ToolBox

    also for more details about operation upon SQLCE db, I loved this blog, and most of the sqlce users all over the world :)