Create a batch file. Save it on desktop and run it as per need just by double clicking.
You can use
SQLCmd
OR
OSql
for it.
Steps:
1. Open one new notepad, put the sql commands that you want to excute, e.g:
USE MyDataBase
go
SELECT * FROM MyTable
go
2. Save the text file with
.sql
extension e.g.: SampleQuery.sql
3. Open another notepad at same folder location, put something like:
osql -S servername -U username -P password <samplequery.sql>
pause
</samplequery.sql>
4. Save this as
.bat
extension e.g.: MySQLQueryBatchFile.bat
5. Double click on this batch file will automatically execute the SQL query
Refer:
MSDN: sqlcmd Utility[
^]
SQL SERVER – sqlcmd vs osql – Basic Comparison[
^]