Link to home
Start Free TrialLog in
Avatar of dgb
dgb

asked on

copy between databases on different servers

Is there a quick way to copy data from on database to another database on a different server.

No import/export but a command something like select ..... from ....

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Kevin Hill
Kevin Hill
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of obahat
obahat

Yes. Define a linked server between the data target server to the data source server: On Enterprise Manager --> Security --> Linked Servers --> Create new.

Set the data source to be OLE DB provider for MS-SQL server.
Set the product name (doesn't really matter much), the data source should be the name of the data source server, and the catalog should be the data source database name.

On security - type the appropriate logins (e.g., if you're an sa, set LocalLogin = sa, and check the impersonate checkmark).
Also check the bullet "Be made ysing the login's current security context".

Finally, on the server options - check the data access, RPC, RPC out and USE REMOTE COLLATION.

Save the new linked server.

For the sake of example, lets assume that the linked server name is <LS>.

The data target machine can now run the query:

SELECT * FROM <LS>.<DataSourceDBName>.dbo.<TableName> and access the data of the data source table.

Hope this helps.

Omri.
try with openrowset method....


USE pubs

SELECT a.* INTO MYTABLE
FROM OPENROWSET('SQLOLEDB','DB_SERVER_IPADDRESS';'DB_USER';'PWD',
   'SELECT * FROM pubs.dbo.authors ORDER BY au_lname, au_fname') AS a

itsvtk
Quick way to add a linked server

exec sp_addlinkedserver @server = N'<SOMELINKSERVERALIAS>',
    @srvproduct = N' ',
    @provider = N'SQLOLEDB',
    @datasrc = N'<DATASBASENAMEOFWHERELINKING>',
    @catalog = N'<CATELOGNAMEOFWHERELINKING>'
GO
Examples
A. Use OPENROWSET with a SELECT and the Microsoft OLE DB Provider for SQL Server
This example uses the Microsoft OLE DB Provider for SQL Server to access the authors table in the pubs database on a remote server named seattle1. The provider is initialized from the datasource, user_id, and password, and a SELECT is used to define the row set returned.

USE pubs
GO
SELECT a.*
FROM OPENROWSET('SQLOLEDB','seattle1';'manager';'MyPass',
   'SELECT * FROM pubs.dbo.authors ORDER BY au_lname, au_fname') AS a
GO

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_oa-oz_78z8.asp

itsvtk