I am not sure what the best design pattern for this problem is so any suggestions would be greatly appreciated. I have two SQL Servers A (with DBs P,Q,R) and B (with DBs X,Y,Z).
What is an efficient way to do a join of tables situated on Server A with those on Server B from command-line? Basically, I am trying to automate a long running list of queries and am not really sure how to proceed.
EDIT: I do not have control over the servers and am not an admin.
At a minimum I would create a Link Server between the two servers. Using something like OPENROWSET will be slower than using a Link Server.
Depending on how fast you need these queries to run you might consider having a nightly process that copies the data from Server A to Server b (or the other way around) so that you don't need to worry about cross server.
There is no way of performing a join across different servers. You can either use a cluster solution on top of those servers to do it for you, or you can do it by yourself - reading from one table, and performing the join manually in your code.
Related
I was wondering how to append data from a SQL Server database to another on a second computer. I've already used the MERGE method by setting the source and target table from the same SQL Server but this time the case is different. I'm trying to retrieve records from 2 standalone POS machines in a grocery stores to the server.
Is there any easy way to achieve this? Is a SQL Server stored procedure using the computer's name or ip address the way to go?
we have solved this problem on many projects and it depends on the scenario of your synchronization, whether it is a manual or automated etc.
In one project, we finally programmed our own synchronization service in .NET. But today we prefer products that offer this functionality out-of-the-box. I personally have experience with DevArt Data Compare, which works great, can be automated and can synchronize data from multiple sources into one (https://www.devart.com/dbforge/sql/datacompare/). In our case, we used it to synchronize from a production server to several test servers via Data Compare and it is orchestrated from one asset.
In addition to Data Compare we also used SymmetricDS (https://github.com/JumpMind/symmetric-ds) which is now unmaintained and is offered in a commercial version (https://www.jumpmind.com/products/symmetricds/overview). It is definitely a good tool but for us the Data Compare from DevArt was better in terms of price and it is able to solve most synchronization scenarios for a good price.
Regards.
My question has to do in regards to the ability of being able to create stored procedures that connect to multiple servers. If anyone's not familiar with it, there's a :CONNECT syntax in SQL that will switch where your query's being run from. For example:
:CONNECT SERVERNAME
SELECT *
FROM Table
GO
This would run the query from where the table is stored as opposed to using linked servers (which cause serious performance issues). Does anyone know if it's possible (and how to achieve it) to create stored procedures that switch between servers? I keep getting various error messages when trying to achieve it. Here would be an example:
:CONNECT SERVERNAME
SELECT *
FROM Table
GO
:CONNECT SERVERNAME2
SELECT *
FROM Table
GO
This would connect to two different servers in the same query.
Thanks
UPDATE - 4.26.2018
All,
We've pretty much decided OPENQUERY is our best solution, at least for stored procedures. Unfortunately, we'll be limited by syntax but performance is MUCH better than using linked servers (which is what we're currently using). I appreciate everyone that's chimed in; Your input was invaluable. If you wish to add anything else, please feel free to do so.
Thanks
Using Linked Servers in a 4-part naming convention will work. It can get ugly fast in regards to performance, so be careful. If you do use Linked Servers, I'd recommend against putting multiple servers in the same SQL statement (including the local server you're on). It isn't terribly efficient. It basically breaks up the query into local and remote queries, it then scrubs the data, and combines it locally before finishing. I've seen users execute queries with multiple servers and take down solid servers in the process.
Another option is the OPENQUERY() method. This still uses a Linked Server, but will send the query to the other server, to process the whole thing there and just ship the data back. This is typically faster and more efficient than the prior.
SELECT
opn.Id,
opn.ColumnName,
opn.AnotherColumnName
FROM OPENQUERY([LinkedServerName],
'SELECT
tbl.Id,
tbl.ColumnName,
tbl.AnotherColumnName
FROM DB.Schema.Object AS tbl
WHERE tbl.ColumnName = ''SomeValue'''
) AS opn
This link gives some more good info: Click Here
SSIS is your best bet here. It's fast, good when using data from multiple servers, and not too difficult to learn (the basics anyway).
So, a few options I've listed...
SSIS - Best option
OPENQUERY() - Better option
Linked Servers - "I guess it works" option
I have two SQL Server databases that are being used for my application.
The issue is that now we have decided to move one of the databases to another new server due to performance issues.
What's the best method to ensure all the joins in the SQL queries will work correctly? Do I need to update each join between the databases to so it can reference the database on the new server?
I have already updated web.config with the change but this wont affect the joins in the queries
Any advice would be great
Thanks
For this you will need to configure the second server as a linked server: http://msdn.microsoft.com/en-GB/library/ms188279.aspx
Queries on the first server can then be updated to access tables on the second.
Be aware though, any queries that join tables across the two servers will usually be very slow - more so if the tables have large numbers of rows.
I need to do some data migration between two oracle databases that in different servers. I've thought of some ways to do it like writing a jdbc program but i think the best way is to do it in SQL itself. I can also copy the entire table over to the database I am migrating to but these tables are big and doesnt seem like a "elegant" solution.
Is it possible to open a connection to one DB in SQL developer then connect to the other one using SQL and writing update/insert functions on tables as if they were both in the same connection?
I have read some examples on creating linked tables but none seem to be oracle specific or tell me how to open the external connection by supplying it the server hostname/port/SID/user credentials.
thanks for the help!
If you create a Database Link, you can just select a from different database by querying TABLENAME#dblink.
You can create such a link using the CREATE DATABASE LINK statement.
It depends if its a one time thing or a normal process and if you need to do ETL (Extract, Transform and Load) or not, but ill help you out based on what you explained.
From what i can gather from your explanation, what you attempt to accomplish is to copy a couple of tables from one db to another, if they can reach one another then its really simple, you could just create a DBLINK (http://www.dba-oracle.com/t_how_create_database_link.htm) and then do a SELECT AS INSERT from either side using the DBLINK for one of the tables and the local table as the receiver or sender. Its pretty straight forward.
But if its a one time thing i would just move the table with expdp and impdp since that will be a lot faster and a lot less strain on the DB.
If its something you need to maintain and keep updated, why not just add the DBLINK and use that on both sides, this will be dependent on network performance though.
If this is a bit out of you depth or you cant create dblinks due to restrictions, SQL Developer has had a database copy option for a while and you can go as far a copying individual tables, but its very heavy on the system where its being run (http://deepak-sharma.net/2014/01/12/copy-database-objects-between-two-databases-in-oracle-using-sql-developer/).
I have a database server that currently has two databases, call them [A] and [B].
[A] is the standard database used for my application
[B] is used by another application (that puts considerable load on the server), however, we use a few tables sparingly (that are shared between my application and the primary application that utilizes [B]). Recently the use of [B] has been increasing and it's causing long wait periods and timeouts in my application.
I'm open to alternative ideas, but at the moment the quickest potential solution I've come up with is to get a second database server and move [A] to that. However, I do need access to some of the tables in [B] - ideally with as little code changes as possible.
We were thinking a setup something like:
Current:
DB Server 1 {[A],[B]} (SQL Server 2005)
New Setup
DB Server 1 {[B]} (SQL Server 2005)
DB Server 2 {[A], [B]} (SQL Server 2008)
Where in the new setup, DBServer2.[B] is a linked table (kind of) to DBServer1.[B]
I looked into linked databases, from my understanding (limited) those work as an alias to a database on another server, which is almost what we want, except it adds the extra server qualifier, and it works on the db level. I'd like to do something like this, but ideally without the server qualifier and on a table level.
So for example, [B] has tables Users and Events. The Users table is updated weekly by batch, and we use it often, so we'd like to have a local copy on the new DBServer2. However, Events we use far less often and needs to be real-time between the two servers. In this case, it would be great to have Events as a linked table.
Further, it would be fantastic if we could use the same markup for queries. Today to query one db from the other we'd do something like
select * from b.events join a.dates
We'd like to continue that, except have the database server know that when we touch events it's really located at dbserver1.b.events.
Does that make sense? I confuse myself sometimes.
Thanks for any help
~P
You can use synonyms for linked objects - http://msdn.microsoft.com/en-us/library/ms177544%28SQL.90%29.aspx
This unfortunately only works for single objects, you CANNOT make a synonym for linkedserver.databasename and then reference synDBName.table.
"Alternative Idea" from me since you said you are open...
How about looking into the cause of the slowness? What is the "Load" you are measuring?
How are your disks laid out on the server?
Maybe you could use more memory, another CPU or Some SQL tuning?
Fixing your issues with a software or hardware fix MAY be faster than getting a server and doing all the installs and then working through the integration problems you may run into.