Replace one database table with another
1 answer
If they are on the same server and have the same table structure, you can do this:
Truncate Table DBProduction.dbo.testTable
Go
Insert Into DBProduction.dbo.testTable
Select * From DBLocal.dbo.testTable
If they are on different servers, you can run the truncate statement as above, then right-click DBProduction and select Import Data. This will launch the wizard and import the data for you.
EDIT: I should also add that if the table structure is different, you should Drop Table DBProduction.dbo.testTable
then use the Data Import Wizard to import (and by default recreate) the testTable into DBProduction.
EDIT 2:
If you want to insert (without listing all columns) when the column is set to "Identity", you need to do the following:
Set Identity_Insert DBProduction.dbo.testTable On
Insert Into DBProduction.dbo.testTable
Select * From DBLocal.dbo.testTable
Set Identity_Insert DBProduction.dbo.testTable Off
This temporarily ignores the seeding of IDs.
NTN
Barry
+3
a source to share