如何运行使用一个BAT文件的脚本? [英] How do I run a script using a BAT file?
问题描述
我想有一个BAT文件打开一个SQL Server脚本。目前,我在SQL文件,这code:
I would like to have a BAT file open a sql server script. Currently I have this code in the sql file:
declare @path varchar(255), @mydb varchar(50)
SELECT @mydb = 'timeclockplus'
select @path = 'C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Backup\'
+ @mydb + '-' + convert(varchar(8),getdate(),112) + '.bak'
BACKUP DATABASE @mydb TO DISK = @path
我如何从一个BAT文件打开此SQL文件?
How do I open this SQL file from a BAT file?
我目前正在这样运行的:
I am currently trying to run it like this:
C:\Program Files\Microsoft SQL Server\80\Tools\Binn\osql -E
-S Sql server-hl7\timeclockplus timeclockplus.sql -oresults.txt
但OSQL中不Binn目录存在,则
but OSQL does not exist in the BINN directory,
推荐答案
您应该调用 SQLCMD 一>从批处理文件中的命令行工具。假设你的SQL文件是backup.sql,命令行会是这样的:
You should invoke the sqlcmd command-line tool from your batch file. Assuming your sql file is "backup.sql", the command line would be something like:
sqlcmd -E -S yoursqlinstance -i backup.sql
-E
使用受信任的连接,用 -U
更换和 -P
如果你需要指定SQL用户名和密码。另请参见这篇文章范例。
-E
uses trusted connection, replace with -U
and -P
if you need to specify a SQL username and password. See also this article with examples.
这篇关于如何运行使用一个BAT文件的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!