Reputation: 73
I have an outdated database, but I would like to keep the data from this database in a separate version of the current working database. I created a copy of my current database, but it has all new data in it. Is there a way to remove all of this data and then import the data from the outdated database?
Upvotes: 5
Views: 2973
Reputation: 3885
Try this to remove data:
-- disable all constraints
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
-- delete data in all tables
EXEC sp_MSForEachTable "DELETE FROM ?"
-- enable all constraints
exec sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"
To import data:
Once completed, return to the Query Window with the scripted objects. Change the USE directive (the first line) to point to the destination database (e.g., USE [Northwind]), and execute the script.
Upvotes: 8