How do I copy records from a table in another database to a table in the current database?

×

INSERT INTO CurrentTableName

SELECT FieldList FROM [OtherDataBase].dbo.OtherTableName

Where FieldList = a comma separated list of fields for the table in question

For example, if you are moving records from the Customers table in the Data_Backup database use the following query:

INSERT INTO Customers

SELECT Cus_No, Name FROM [Data_Backup].dbo.Customers

In many cases you may need to construct a WHERE clause that only copies records that aren't already there, use the following query:

INSERT INTO Customers

SELECT Cus_No, Name FROM [Data_Backup].dbo.Customers

WHERE Cus_No NOT IN (SELECT Cus_No FROM Customers)

In other cases you may need to clear the table before running the query