Sql-server – SQL Server command line usage? Is it possible

sql serversql-server-2008windows

I've been trying to use the SQL Server Management Studio 2008's built in "Solution Explorer" to manage a project and after 2 weeks of struggling with it, I've decided I don't really care for it. It's "convenience" features are actually quite a hindrance.

Unfortunately, the place where I work is a MS shop, and is pretty stuck in their ways. I want to go back to the command line (I crave Vim!). I've installed a local subversion repository with a TortiseSVN front end, to replace the above mentioned "Solution Explorer" and have it running quite well. I have also installed Vim and while still working on customizing it, have it humming.

However, the one thing that I am yet to find a solution to is how to run commands to SQL Server via the command line. I'm used to MySQL/Postgres command line prompt since that is what I have used in the past and was using while going through my classes. However, I can't seem to find a way to execute my scripts via the command line in windows. I currently edit them in Vim, refresh the page in SSMS, and execute. I would prefer to not even touch SMSS unless needed.

I've seen posts suggesting sqlsharp, but when I went to the page, I get the feeling that isn't quite what I'm looking for.

–edit

I really wish that it was possible to have 2 answer check marks. P. Campbell has the technical right answer, and I've tried it a few times (I keep getting an error when I try sqlcmd… In researching that it's how named pipes is operating… Even though I have it set up and enabled, it doesn't seem to work.)

After trying that and not having any success, I tried the just copy and paste into Management studio method, but that was ridiculous… So I decided that maybe HardCode is correct too.

Best Answer

Have you considered SQLCMD?

Here's an article on Using the SQLCMD command line utility.

You can execute adhoc SQL statements, or run .sql scripts.

The following example runs the C:\MyScript.sql script from the command line and outputs the queries and results to a text file located at C:\MyResults.txt.

C:\Windows>sqlcmd -S NOTTINTRA3\SQL2005 -i C:\MyScript.sql -o c:\MyResults.txt -e

enter image description here