从命令行执行sql脚本 [英] execute sql script from command line
问题描述
我需要使用批处理文件,一个简单的例子来改变一个数据库,删除表。 I'm使用本地sqlex preSS(SQL Server 2008 R2中)与用户sa及其密码。如何将bat文件呢?我怎样才能在脚本中指定口令,而我使用sql前preSS?谢谢你,我是新与此有关。
I need to alter a database using a batch file, for a simple example, drop a table. I´m using local sqlexpress (sql server 2008 r2) with user sa and its password. How would the bat file be? How can I specify in the script the password and that I use sql express? Thank you, I'm new with this.
推荐答案
看看在 SQLCMD
工具。它可以让你在命令行中执行SQL。
Take a look at the sqlcmd
utility. It allows you to execute SQL from the command line.
<一个href=\"http://msdn.microsoft.com/en-us/library/ms162773.aspx\">http://msdn.microsoft.com/en-us/library/ms162773.aspx
这一切都在那里的文档中,但语法应该是这个样子:
It's all in there in the documentation, but the syntax should look something like this:
sqlcmd -U myLogin -P myPassword -S MyServerName -d MyDatabaseName
-Q "DROP TABLE MyTable"
这篇关于从命令行执行sql脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!