Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy Data from a table in one Database to another separate database

Tags:

sql

sql-server

Basically I have a two databases on SQL Server 2005.

I want to take the table data from one database and copy it to another database's table.

I tried this:

SELECT * INTO dbo.DB1.TempTable FROM dbo.DB2.TempTable 

This didn't work.

I don't want to use a restore to avoid data loss...

Any ideas?

like image 420
Gabe Avatar asked Jun 02 '09 17:06

Gabe


People also ask

How do I copy data from one database table to another database?

Right-click on the database name, then select "Tasks" > "Export data..." from the object explorer. The SQL Server Import/Export wizard opens; click on "Next". Provide authentication and select the source from which you want to copy the data; click "Next". Specify where to copy the data to; click on "Next".


1 Answers

SELECT ... INTO creates a new table. You'll need to use INSERT. Also, you have the database and owner names reversed.

INSERT INTO DB1.dbo.TempTable SELECT * FROM DB2.dbo.TempTable 
like image 91
Tom H Avatar answered Oct 16 '22 02:10

Tom H