Execute SQL script from command line(从命令行执行 SQL 脚本)
问题描述
我需要使用批处理文件更改数据库,举个简单的例子,删除一个表.我正在使用带有用户 sa
及其密码的本地 SQL Express (SQL Server 2008 R2).
I need to alter a database using a batch file, for a simple example, drop a table. I´m using local SQL Express (SQL Server 2008 R2) with user sa
and its password.
bat 文件会怎样?
如何在脚本中指定密码以及我在 SQL Express 中使用的密码?
How can I specify in the script the password and that I use in SQL Express?
推荐答案
查看 sqlcmd
实用程序.它允许您从命令行执行 SQL.
Take a look at the sqlcmd
utility. It allows you to execute SQL from the command line.
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 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从命令行执行 SQL 脚本


基础教程推荐
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- Sql Server 字符串到日期的转换 2021-01-01