Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Management Studio command line?

Is there a command line interface where I can run a script that says, for example: Connect to server a Run query 1 Connect to server b Run query 2 Run query 3

I tried searching online but couldnt find anything built into SQL Server Management Studio. Thanks!

like image 633
Andrew Avatar asked Aug 17 '12 15:08

Andrew


Video Answer


2 Answers

The sqlcmd Utility

http://msdn.microsoft.com/en-us/library/ms162773.aspx

It usually ships with the SQL Server installer and is located in the following directory by default:

C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE
like image 93
CodeZombie Avatar answered Oct 11 '22 09:10

CodeZombie


If you want to export in/out there is a command-line utility called BCP that will let you execute these types of processes.

bcp Utility

The bcp utility bulk copies data between an instance of Microsoft SQL Server and a data file in a user-specified format. The bcp utility can be used to import large numbers of new rows into SQL Server tables or to export data out of tables into data files. Except when used with the queryout option, the utility requires no knowledge of Transact-SQL. To import data into a table, you must either use a format file created for that table or understand the structure of the table and the types of data that are valid for its columns.

like image 41
Taryn Avatar answered Oct 11 '22 09:10

Taryn