Hey experts.

I have two database, i want to fetch values from one of the table from one database and then insert that into another table on another databse, server is same.

can i do it? if yes please give some suggestions how to make it hapoen.

many thanks in advance.

Recommended Answers

All 4 Replies

Something like..

INSERT INTO DB1.TABLE1(*FIELDS*)
SELECT *FIELDS* FROM DB2.TABLE2

Yes, just as you normally would with your insert into statement. Just make sure that you qualify the statements by specifying the dB name.

For example, in the select statement, SELECT FieldName1, FieldName2 from DB1.dbo.tableName

thanks for reply but, how to make connection with two databases then?

Ok, the assumption was that both databases were on the same server. If this is not the case, you would have to depend on your DB to allow for connections to a remote DB. In the case of MSSQL, you can create "linked servers" so that when you refer to the second DB, you can access it even if its on a remote server.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.