从命令行执行sql脚本 [英] execute sql script from command line

查看:103
本文介绍了从命令行执行sql脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用批处理文件,一个简单的例子来改变一个数据库,删除表。 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆