How to Execute SQL Server query (procedure) from another PC in network - sql

Situation now
We have a netrowk set up. Some PCs have SQL Server 2012 installed, some don`t.
Is it possible to write a stored procedure and have it invoked/executed by another user/PC without SQL Server? For example by some .bat/.cmd script, I don`t know.
Desired situation
I write SQL query on my SQL Server management studio.
I save the query as a stored procedure. <-- up to here I am OK.
I do something that makes the procedure availible to other users. The advice I get from this question (I hope).
Other colleagues execute the procedure.
They get a result of the query in a CSV.

The client computers that need to run the stored procedure could install the sqlcmd utility. This allows for the execution of sql commands on another SQL Server.
SQLCmd -S<<SERVERNAME\INSTANCENAME>> -Q "Execute dbo.YourStoredProcedure"
And then have your stored procedure save the CSV file to a network drive or send it via e-mail.
Another way to retrieve data could be using the BCP utility. In this way the user could connect to your server, execute the query and receive a CSV file to a specified location on their computer.
In both cases it involves installing an additional program on the client computer.

You don't need SQL Server installed in the client machines to run queries or execute procedures. At most, depending on which programming language you are are using, you need the client installation for SQL Server. This is true for any DBMS, even Microsoft SQL Server 2014.
If you implement you code in Java, for example, you don't need even the MS SQL Server client. The JDBC driver for MS SQL Server is enough. It can be download from Microsoft and is not part of the SQL Server client installation.

Related

How to connect to an Oracle db using a stored procedures within a Microsoft SQL server?

I need to verify data between and Oracle db and a Microsoft SQL server db to verify that if there differences between the two and then update the Microsoft SQL server with any changes there may be
You can use/create database links. That means that you have to have oracle client installed on your sql server though.
You may configure connection to Oracle as linked server in SQL Server and use MERGE to synchronize date in SQL Server agent's job, for example. Fetching data from linked server could not the fastest thing in the world, but it is very easy to configure and use.
Use OPENQUERY with TNS alias already configured in tnsnames.ora file

Issuing Teradata SQL Assistant query via script

I use Teradata SQL Assistant to run SQL queries against a DB2 database accessed via an ODBC connection. This is an entirely interactive process whereby I first start the SQL Assistant app, then connect to the correct data source and finally write and execute my query.
What I would like to do is to be able to achieve the same result, i.e. get the result set from a query, but via some sort of script, which would connect to the the data source and run my query.
Is this possible?
Yes this is possible. Install the IBM Data Server Client software appropriate for your version of DB2, then use the DB2 command line processor with the -f option, as described in the manual.

SQL Server stored procedures automatically recompiled?

If I use a web application Web Data Administrator and I edit the stored procedures SQL query, does it recompile on it's own? (new to SQL Server and this side of the database development)
MSSQL Server does maintain a cache of query plans, but this is not the same as compiled code.
The SQL Server manages this cache and can be the source of some pain if it caches a plan that is non-optimal. Though this has happened to me less than 5 times in 15 years (and that seemed to be a problem with a particular server), its best to let SQL server handle this and not touch it.
You can force SQLServer to recompile by supplying the WITH RECOMPILE option. Same caveat applies, unless you have a substantial reason to, DONT.
SQL is a scripting language, which means the code you write is not compiled. Rather, it is stored on the server to be used later.
When you edit a stored procedure, you can execute an ALTER script, or a DROP then CREATE script. This sends the text in your Web Data Admin (or SSMS) window to the server, issuing a command that tells the server to store this new query as a procedure for later use.
So, in short, yes, if you execute an ALTER script.

Backup DB on Remote SQL Server Express

I need to create a TSQL script to backup a db on a remote SQL Server Express (2005). I have a SQL Server 2005 on another box. Not sure how I can run the script from this SQL Server 2005 to do the backup job.
The script is something like this:
RESTORE DATABASE [myDB] FROM DISK = N'C:\Tmp\myDB.bak' WITH FILE = 1,
NOUNLOAD, STATS = 10
Actually, I tried this SQL script on the remote SQL Server Express by using SQL Server Management Studio Express and it runs OK. The reason I ask this question is that I can schedule a job on SQL Server 2005, but I cannot create a schedule job on the remote SQL Server Express.
Another way, I think, is to create a SQL SP on the SQL Server Express first. Then I'll write a simple console application to connect to the SQL and run the SP as a Windows Scheduled job.
There is no need to do this by TSQL. SQL Server (also Express) includes a utility called sqlmaint.exe, which allows you to perform backup operations on a local or remote SQL server. Simply write a batch file calling sqlmaint with the correct command line parameters (documentation) and put this batch file in Windows Scheduler.
If you still want to do it by TSQL, SQL Server also contains osql.exe, which allows you to execute arbitrary SQL statements on a local or remote server. Again, you can automate it using simple batch files.
EDIT: If you want to call the TSQL script using your own application, it might be helpful to know about your programming language or data access technology of choice.

Moving data between oracle and sql server using Linked server

I have set up Oracle Linked server on Sql Server 2005 box using Oracle provider oledb and its working fine from sql server 2005 to oracle 9i, i.e. When i run distributed query from sql server i get data from oracle server to sql server. Now I don't have any clue how do i run distributed query from Oracle server and get data from sql server repeatedly. Do i have to set up Dsn ? What other things i have to set up before i run query from oracle server?
FYI : Oracle server is Sun solaris server and SQL server is x64 Windows Server 2003. Sql server has oracle client installed on it with odac drivers for ORACLE Provider for OLEDB.
I am going to use loadjava to load java into oracle and than move data between both repeatedly. (Java, Stored procedures & Triggers from oracle to get data from sql server)
Here is one way. DG4ODBC setup guide here.
This might help, too.
linking databases is the first phase. After that you may face the problems we faced, like not being able to delete fetched rows from Sql Server to Oracle Server remotely.
I will post a question about that, it is odd that our procedures used for data synching do not respons the same.