INSERT from one database to another?

  • Thread starter Thread starter Vagabond Software
  • Start date Start date
V

Vagabond Software

INSERT INTO db2.dbo.myTable (id, person) SELECT id, person FROM
db1.dbo.myTable WHERE id = 1

I'm trying to do this using an SqlTransaction. I am assigning the above SQL
statement to the CommandText property of the SqlCommand object associated
with the transaction. Do I need to open two DbConnection objects to the
instance of SQL Server where these databases reside? Do I only need one
open DbConnection? Is there a better way this needs to be done?

Any help is greatly appreciated.

Carl
 
You can reference a table in another database on the same by using:
databasename..tablename.

So something like:

SELECT * FROM myotherdatabase..sometable.
 
Marina said:
You can reference a table in another database on the same by using:
databasename..tablename.

So something like:

SELECT * FROM myotherdatabase..sometable.

Thanks. I actually ended up using [myotherdatabase].dbo.sometable and it
worked. I appreciate the help.

Carl
 
Back
Top