I would like to create a db reset script.
1: Drop all FK constraints
2: Truncate all tables (I can manage this, but help appreciated)
3: Recreate all FK constraints.
How can I generate step 1 and 3 from the current state of the db?
I would like to create a db reset script.
1: Drop all FK constraints
2: Truncate all tables (I can manage this, but help appreciated)
3: Recreate all FK constraints.
How can I generate step 1 and 3 from the current state of the db?
First you need to look up all foreign keys for the table in questions (or a list of tables from the DB first), then disable all foreign keys -by their name-, do the truncate and re-enable keys. You might need dynamic sql throughout this process.
Technically, you can put this fairly simple script/SP together in minutes after 2-3 mins googling for the solution.
If it's about mass-destroying all data, I'd also consider dropping the DB (or tables in question) and re-creating from a .sql, as that probably is faster.