Alternatives to sqlcmd/best practice - sql

I have created a sql query that updates certain tables taking a CSV file as the input.
I want my co-workers to be able to execute this query as easily as possible. At first, I thought a batch file using sqlcmd was the best solution.
The end product works on my computer, because I have SSMS installed, but no other computer is able to properly launch the batch file.
What is the best way for my end-users to run an sql query? I have thought/researched these solutions:
-Install SSMS or the required tools(don't want each user to have to do this.)
-Install Psexec tools to allow for remote batch launching (also don't like this.)
Is there a better way?

Check SQLS*Plus from www.memfix.com - works the best.

Why don't you create a C-Sharp or VB.Net program that executes the proc and distribute the program to your users?

You don't have to install all of SMS. You can just install SQLServer2008CmdLnUtilsx86.msi for SQL 2008 or go here to get SQLCMD for SQL 2012. http://www.microsoft.com/en-us/download/details.aspx?id=36433. Just be aware that if you install SQLCMD in a bat file and then attempt to use SQLCMD after installing it in that same bat file you have to specify full path to SQLCMD because PATH value is loaded at time bat was started and SQLCMD was not yet available at that time.

Related

Unable to run .sql file in SQL Server

I have a .sql dump file 20 gb and I am trying to run it on Mysql workbench using run script and after successful execution, using SSMA I'll migrate the data from Mysql workbench to SQL Server. I have migrated the data this way many times successfully however for 20 gb file it seems very time-consuming. Please let me know if there is any alternate way to achieve this quickly. I have followed the following link:
Steps to migrate mysql tables to sql server using SSMA!
From your Title "unable to run .sql file in SSMS" and "I have a .sql dump file 20 gb" are you trying to open a 20GB .sql in SSMS? That's never going to work. SSMS is a 32bit application, so the maximum addressable memory is 2GB. If you want to run your .sql file, I suggest using sqlcmd.
Open up Powershell, and then run the command below replacing the appropriate parts:
sqlcmd -S {Server Name/ServerIP} -U {Your Login} -i {Your full path to your script}
You'll be prompted for your password and then you the file will be run. So, as an example, you might run:
sqlcmd -S svSQL2017 -U Larnu -i \\svFileServer\SQLShare\Scripts\BigBatchFile.sql
If you are using integrated security, then don't pass the -U parameter for the command.
Edit: This answer is no relevant to the OPs question, as they were using "SSMS" as a synonym for SQL Server, which it is not. I have left this here for the moment so the OP can review my comments, and I will likely remove this answer at a later point.

A batch that can write into a .exe cmd prompt?

I would like to make a batch file that can write sql request into an .exe that is running as a cmd prompt window.
My idea was to put my sql script into an .txt file that the batch request and insert into my second prompt window.
I've found something about:
Type 'mytext.txt' | myexe.exe
But its not working.
What I want to do is a Batch that send my sql request into that .exe run as a cmd prompt, so I can automate that process.
Any idea?
Thanks
Depends heavily on the capabilities of that exe-file.
What does it poll for ? Is it written to handle pipes ?
https://technet.microsoft.com/en-us/library/bb490982.aspx gives you an overview of the command redirection operators.
Not knowing what the exe is capable of makes this question really hard to answer.

Installing UDFs in Netezza (Aginity)

I'm trying to use the GROUP_CONCAT() UDF in a Netezza query but I have no idea how to install the function into my database! I've downloaded the c++ code and there's an installer in the folder but I don't know how to run that!
I've been googling it for about a day now with no luck. I'm using a Windows computer and am running Netezza through Aginity.
Would anyone be able to help me out?
Thanks in advance,
Conor
UDFs are installed through a command line interface on the Netezza host, and not through SQL. You will need to sftp the source code to the host, connect with an SSH tool (e.g. putty or the Aginity SSH client under Tools->SSH Terminal), and run the install script from there. Your database login will not work for logging into the host. You may have to work with your administrator to get access.
Here is an exmaple of innstalling the c++ version of GROUP_CONCAT into a database called TESTDB.
[nz#netezza group_concat]$ ls -1
GroupConcat.cpp
GroupConcatSep.cpp
install
[nz#netezza group_concat]$ ./install testdb
CREATE AGGREGATE
Created uda
Done
CREATE AGGREGATE
Created uda
Done

How can I execute SQL scripts using TeamCity?

I´m new with TeamCity and I don´t know how to run SQL scripts with it.
Is the way simply selecting the path of those scripts in a Command Line Build Runner ?
I´m pretty lost.
Regards.
In a command line build step:
Command executable: c:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe
Command parameters: -S <server> -i <path_to_file> <== Note: that's a capital -S!
You may need to change the 100 to something else, depending on the version of the SQL Server tools that you have installed on the build agent.
I believe that SQLCMD / SQLPLUS / MYSQL are available as standalone executables which you can install on the TeamCity server.
Microsoft® SQL Server® 2008 R2 Feature Pack
Oracle SQL Plus
MYSQL Command Line
However, without knowing your actual SQL Platform this may differ and the provider should have an alternative.
You can then create a Command Line Runner to call the executeable and pass in the parameters required, which are further explained here.
Using the sqlcmd Utility
Using sqlplus utility
If you are looking at doing Database Migrations as part of your CI process, it would also be worth checking out RoundhousE

Is there a way to directly compress/zips the result from a SQL query?

Off late I have been dumping relatively large tables using SSMS. The usual way is to set Query->Results-To->File, 'Execute`, choose a file and let the SQL query run. After it finishes, I usually zip the file and then transfer it to my local machine. This has obvious problems of the host machine running out of space during overnight SQL queries.
I was wondering if there is a way to compress the output from SSMS directly without having to wait until it dumps the results from the entire query. Any suggestions? The host machine is pretty restricted in what it allows me to run on it so a suggestion that requires minimal third-party software would be great.
Run the queries from sqlcmd instead and pipe the output into a command line zip (you'll need to install one, see What's a good tar utility for Windows?). Or you can use PowerShell that can zip out-of-the-box, including piped input, see Compress Files with Windows PowerShell then package a Windows Vista Sidebar Gadget, this requires no additional tools as PS is already on your host server (although on second read I think the PS solutions, as in the link, still requires a deflated file first, cannot compress on-the-file).
Sample query using sqlcmd and 7zip:
sqlcmd -S <DATABASE> -s <COLUMNSEP> -Q "SELECT ..." | .\7za.exe a -si <FILENAME>
Remember to use the -Q (run query and exit) and not the -q (run query) or else this won't work.