SQL Server, How to execute T-SQL commands from the command line (attention this post may contain easy but useful tips 😏 )
Hello friends,
You know, i love “useful but fast & easy” tips!
The question of today:
Have you ever needed to run T-SQL commands from the command line? Yes?
So, How to do it?
Well, an easy way is to use the sqlcmd command.
But what is the SqlCmd?
The SqlCmd is a command line utility that is part of the standard installation of SQL Server and that you can run from the command prompt.
First you need to prepare a script that contains the T-SQL commands to execute.
In my example i saved myscript.sql in C:\TEMP folder.
Second, just open the command prompt
And type in:
sqlcmd -U "XX" -P "YYYY" -S "ZZZZ" -i “c:\temp\MyScript.sql”
You need to specifiy only the login information using:
-U username
-P password
-S the server name
-i the location of your script
Et voilà!
That's all for today!
Luca
I guess there is a need to look up for more and more SQL operations and other utilities and dig deeper to find out solutions for database complications.
ReplyDeleteSQL Server Load Soap API