Execute stored procedure on multiple linked servers vs separate connections - sql-server

I have to get some data from multiple databases using stored procedures. I am using SQL Server 2008 R2 and 2014.
I could have each stored procedure on his own server, or all procedures on a single server with linked servers to the rest of databases.
I am wondering on the pros and cons for each method in the terms on performance, as the returned data on a daily basis use will be around 2000 rows, but it could reach at a maximum ~30000 rows.

The best practice is that each stored procedure execute on his own server. Even you will call all procs from one server with linked server.
When you call a procedure that contains a linked server the data is load before the processes begin. But you call a procedure through the linked server the proc will process on the own server before answer you.

Related

Equivalent to Linked Tables in MS Access on SQL Server

After searching I did not find answer to my question.
If I have linked table in Microsoft Access I have table updates every time if data changed.
I am now using SQL server and I have a stored procedure collecting data from many tables. I want this procedure to be executed once and the results to be stored in a table, or update if the data has changed.
How can I achieve this in SQL Server?

Call SQL Server stored procedures from SAP HANA

We are using a SAP HANA environment to connect to various databases (SQL Server, Oracle, Teradata). Now one of our sources (the SQL server one) contains a lot of stored procedures to calculate transient values. We would need to have these values as well in SAP HANA and are thinking about the best way:
Ideally, HANA can call the stored procedure of SQL and get back the result data, but I could not find information about this. Is this possible?
Another option is to write a little program (Java) in HANA that can call the stored procedure on SQL Server and then give back the data (either directly, or by storing is some temporary table on SQL side and then read in with HANA).
Other ideas?
Does anybody have suggestions on this?
As long as you can run SQL queries you could see if using OPENROWSET would work for you.
Using OPENROWSET with stored procedure as source you can then consume data as it would SQL rowset.
SELECT * FROM
OPENROWSET ('SQLOLEDB','Server=(local);TRUSTED_CONNECTION=YES;','exec master.dbo.sp_who')
AS tbl
Using SAP HANA Smart Data Integration (SDI) remote sources, you are able to access/federate to remote tables, views and stored procedures.
First create the remote source, then wrap the Stored Procedure in a Virtual Procedure, these can be created via the Web IDE or SQL. You would use the CREATE VIRTUAL PROCEDURE statement as described below.
Create Virtual Procedure with Web IDE
CREATE VIRTUAL PROCEDURE via SQL

Running Stored Procs on Different Databases through Agent Job

I have a list of three stored procedures that need to be ran daily on a number of separate SQL databases. Each database is named differently, but the stored procedures on each are the same.
I have extremely limited knowledge on anything other than basic queries, but was thinking I could have a SQL Server Agent job on a database I set up as Master. Then I have that server push that job to the other databases once I configure those as Targets. My issue is that in thinking through this, the database names are different and within the SQL Server Agent wizard I can only set the database to what's currently on master instance.
What would be the best approach to executing this looping through servers to run the stored procs?
What you're looking for is a linked-server. They allow servers to be linked so that you can call objects from one server to another. They are very easy to setup. In your case, you'll need to create 3 linked-servers on the main server, which will be used to schedule the job. A linked-server will allow the main server to link to listed servers. Here are tutorials of how you can create a linked-server.
Once you've created a linked-server you'll simply create a job that will execute all 3 sprocs, something like this:
EXEC [server1].[database].[schema].[sp_name];
EXEC [server2].[database].[schema].[sp_name];
EXEC [server3].[database].[schema].[sp_name];

Execute 'View' residing in a remote server from a stored procedure

How to get the results (pass parameter also) of a view of a remote server from a stored procedure?
The view is in a separate server from the current server where the stored procedures exist.
Thanks.
You could use the Linked Server feature of SQL Server inside your stored procedure:
A linked server configuration allows
Microsoft SQL Server to execute
commands against OLE DB data sources
on different servers. Linked servers
offer these advantages:
Remote server access
The ability to issue distributed
queries, updates, commands, and
transactions on heterogeneous data
sources across the enterprise.
The ability to address diverse data sources similarly.
You would have to write your query inside your stored procedure this way for example:
SELECT *
FROM MyRemoteServer.MyDB.dbo.MyView
WHERE MyViewColumnX = #ParameterY
Create a linked server on your main SQL Server, creating the link to your remote server.
The fact you have a view on the remote server is good, it provides a layer of abstraction to your data. You can specify a login for the linked server that has permission to read that view only. You could also modify the view in the future (add a "where" clause for example to improve performance) with no front end changes required.
I would also add another view on your main server that selects from the view on your remote server: -
create view vwMain as select col1, col2 from RemoteServer.DB.dbo.RemoteView.
That way you can reference vwMain throughout your code (within many stored procedures) without continually referencing the remote server. This way, should your remote server change or you move the data to your main server, it is one simple change to vwMain and all your code continues to work.

Call a sproc from another sproc on a different machine

I am using SQL server 2000.
I have a stored procedure sitting on machine A. I want to call this stored procedure from within a stored procedure on machine B. How do I go about this?
You could use the Linked Server feature of SQL Server.
A linked server configuration allows
Microsoft SQL Server to execute
commands against OLE DB data sources
on different servers. Linked servers
offer these advantages:
Remote server access
The ability to issue distributed
queries, updates, commands, and
transactions on heterogeneous data
sources across the enterprise.
The ability to address diverse data sources similarly.
A call could look like this:
exec MyRemoteServer.MyDB.dbo.sp_MyStoredProc
Read this blog post. Essentially, if the server is already set up as a linked server you can use EXEC RemoteServer.DatabaseName.DatabaseOwner.StoredProcedureName

Resources