Popular Posts
-
Rules of Coding The most important language you will ever code in: English (or the common spoken language used in your company). -- So...
-
Here is how to parse a date that is in the format of mm/dd/yyyy: // Parse string with date but no time component. string dateStr...
-
The object of copying code is to save time. However, I have discovered by sad and repeated experience that copying code more often than not...
-
This blog is to let you know how to use the SQL import wizard. It is very interesting. The most important thing to remember is that you ca...
-
Tonight I attended a conference hosted by The Church of Jesus Christ of Latter-day Saints. It's topic was the protection of the institu...
-
Here's how you create a CSV file that will open in Excel. It is a csv (Comma spaced Value) file with double quotes " as identifier...
Wednesday, February 2, 2011
Connecting Two Remote Databases in a single SQL Query
Background
Every Microsoft SQL Server database, there is a folder called Server Objects. Within that folder there is a folder called "Linked Servers". If you right click on that folder and hit New Linked Server, it will open up a new linked server wizard.
New Linked Server Wizard
By following the steps there, you can setup a new linked server.
First, type in the name or IP address of the server where it says "Linked server". For example: "1.0.9.46".
For a remote SQL database choose SQL Server as the server type. Then select the security page from the left, and enter the login credentials under the "Be made using this security context" option: Enter the username where it says remote login, and the password below where it says "With password."
Creating a Query using the Linked server.
Once your linked server is setup, you can execute a query like the following:
SELECT *
FROM
[1.0.9.46].DatabaseName.dbo.tableName t
JOIN users ON user.ID = t.userID;
Enjoy!!!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment