473,388 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

load data from one DB in a server to another DB in another server

22
I am trying to do the following data loading.

Scenario: I have an login account UA, password UA123 in sql server A. I also have an login account UB, password UB123 in sql server B.

In server A, there is a table TableA (COL1 INT, COL2 VARCHAR(20)) in database DBA. In server B, there is a table TableB(COL2 VARCHAR(20)) in database DBB.

Now assuming I login on server B, and wish to insert the COL2 of TableA into TableB. How to write a SQL or T-SQL for this task?

Thanks in advance.

CUQ
May 8 '12 #1
3 2557
Rabbit
12,516 Expert Mod 8TB
If you have a linked server, you just need to qualify it.
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM linkServer.dbName.schemaName.tableName
If you don't have a linked server, you can use an OPENDATASOURCE.
Expand|Select|Wrap|Line Numbers
  1. SELECT   *
  2. FROM      OPENDATASOURCE(
  3.          'SQLOLEDB',
  4.          'Data Source=ServerName;User ID=MyUID;Password=MyPass'
  5.          ).dbName.schemaName.tableName
May 8 '12 #2
cuqsy0
22
@Rabbit
Thanks for the reply. I like most your second method, and try to use it. However, it seems there is a little problem.

Here is my test result using SQL Server 2012. Instead of using two servers, I run the query on one server, and with different user accounts. I set up two user accounts (UA and UB) on the same SQL server "localhost". UA account has full access to AdventureWorks2012, and UB account has no access to AdventureWorks2012. I logon as admin and did two steps. First I did a reconfigure, and it was sucessful. Second, I tried to SELECT. If I use admin account, the select is successful, but it has no practical meaning because admin already has access to AdventureWorks2012. If I logon UB and tried to SELECT, I got an error:

-------------------------------------------------
sp_configure 'show advanced options', 1
reconfigure
GO
sp_configure 'Ad Hoc Distributed Queries', 1
reconfigure
GO
-------------------------------------------------
SELECT * FROM OPENDATASOURCE
('SQLOLEDB', 'Data Source = localhost; User ID = UA; Password = UA123 ' )
.[AdventureWorks2012]
.[HumanResources]
.[Department]
-------------------------------------------------
The error message is "Msg 7416, Level 16, State 2, Line 1
Access to the remote server is denied because no login-mapping exists." Any idea?

--CUQ
May 8 '12 #3
cuqsy0
22
@Rabbit
Finally I choose your method one. Here is my result and it works fine.


--------------------------------
Expand|Select|Wrap|Line Numbers
  1. USE master;
  2. GO
  3.  
  4. -- The remote server name is assumed to be 'RemoteServerIPAddress\sqlexpress,1433'
  5.  
  6. EXEC sp_addlinkedserver 
  7.    N'RemoteServerIPAddress\sqlexpress,1433',
  8.    N'SQL Server';
  9.  
  10. EXEC master.dbo.sp_addlinkedsrvlogin  @rmtsrvname =  'RemoteServerIPAddress\sqlexpress,1433' 
  11.       ,  @useself =  'FALSE'  
  12.       ,  @locallogin =  'UB'  
  13.       ,  @rmtuser =  'UA'  
  14.       ,  @rmtpassword =  'UA123'
  15.  
  16. EXEC sp_serveroption @server =  'RemoteServerIPAddress\sqlexpress,1433' 
  17.       ,@optname =  'connect timeout'     
  18.       ,@optvalue =  '60' 
  19.  
  20. ------
  21. USE AdventureWorksDW2012
  22.  
  23. CREATE TABLE TABLEB(COL2 VARCHAR(255))
  24.  
  25. INSERT INTO TABLEB(COL2) 
  26.   SELECT AccountType 
  27.     FROM [RemoteServerIPAddress\sqlexpress,1433].[AdventureWorksDW2012].[dbo].[DimAccount] 
  28.  
  29. GO
  30.  
--------------------------

Thanks a lot!

--CUQ
May 9 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Pieter Van Waeyenberge | last post by:
Hello i *had* it working ... i have everything in place as all documentation and fora stated.. but yet i AGAIN get the error: "The used command is not allowed with this MySQL version" in...
0
by: Montagna, Dan | last post by:
------_=_NextPart_001_01C35B55.62B4A6E0 Content-Type: text/plain; charset="iso-8859-1" Hello, I'm a very new mysql/php user and am trying to use the load data infile command without luck. I'd...
0
by: Donald Tyler | last post by:
Then the only way you can do it that I can think of is to write a PHP script to do basically what PHPMyAdmin is trying to do but without the LOCAL in there. However to do that you would need to...
0
by: JohnLH | last post by:
Hi, I am having an issue with the LOAD DATA LOCAL FILE command on the latest 3.0.9 JDBC Driver. The command works on Windows, but doesn't seem to work on OSX and Linux. The error that I get on...
2
by: Alex Hunsley | last post by:
I'm using a mysql monitor under cygwin (on win xp) to do a 'load data infile' to put some data into a mysql database (I'm using the xampp bundle).. My problem is that I have a four line CSV file...
1
by: Ray in HK | last post by:
What are the differences between LOAD DATA INFILE and LOAD DATA LOCAL INFILE ? I found some web hosting company do not allow using LOAD DATA INFILE but allow LOAD DATA LOCAL INFILE. The reason...
1
by: Uthuras | last post by:
Greetings, Machine : Pentium IV Os Windows 2000 server Product : DB2 UDB Release : 7.2 We are fail to load the following data file format into db2 database table that has long varchar...
3
by: subaga | last post by:
Hi, I have to load data into a table with one of the columns defined as NOT NULL, but the file does not have data for it. i would like to load a constant value for this column and the constant...
3
by: nsh | last post by:
mailing.database.mysql, comp.lang.php subject: does "LOAD DATA" EVER work?!? I've tried EVERYTHING! version info: my isp is running my web page on a linux box with php ver. 4.4.1 according to...
1
by: Freedolen | last post by:
Hi, I have checked with some sample data and found inserting of data using 'insert command' takes more time than using 'load data' command to load data from another file. What is the process...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.