直接从快捷方式或Windows资源管理器运行SQL查询 [英] Run SQL Query Directly from shortcuts or Windows explorer
问题描述
您好,专家,
我开发了一个SQL查询,该查询可以与SSMS一起正常运行.
我想通过双击Windows资源管理器中的文件名来运行它.
请给我个主意.
--- Anil Kumar
Hi Experts,
I have developed a SQL Query which is running fine with SSMS.
I want to run it by double clicking the file name from windows explorer.
Please give me the idea.
--- Anil Kumar
推荐答案
创建一个批处理文件.将其保存在桌面上,然后双击即可根据需要运行.
您可以使用SQLCmd
或OSql
.
步骤:
1.打开一个新的记事本,放入要执行的sql命令,例如:
Create a batch file. Save it on desktop and run it as per need just by double clicking.
You can useSQLCmd
OROSql
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.保存扩展名为.sql
的文本文件,例如:SampleQuery.sql
3.在相同的文件夹位置打开另一个记事本,并输入以下内容:
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.将其另存为.bat
扩展名,例如:MySQLQueryBatchFile.bat
5.双击该批处理文件将自动执行SQL查询
参考:
MSDN:sqlcmd实用工具 [ SQL SERVER – sqlcmd vs osql –基本比较 [ ^ ]
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[^]
您要挂钩 ^ ]和 ^ ]
you want to hook osql.exe[^] up with File Associations[^]
这篇关于直接从快捷方式或Windows资源管理器运行SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!