Delete all data from a SQL Server database, and then re-enter data from another database?

I have an outdated database, but I would like to save 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 the new data. Is there a way to delete all this data and then import data from an outdated database?

+5
source share
1 answer

Try deleting 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:

  • In Microsoft SQL Server Management Studio Express, expand the databases.
  • Right-click on the database containing the objects that you want to copy to another database.
  • "", " "... Script, :
  • ( ),
  • ( ),
  • , Script ( , ..),
  • , , , Script ( Script ).

. USE ( ), (, USE [Northwind]) script.

+8

All Articles