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 脚本


- 更改自动增量起始编号? 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- SQL 临时表问题 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01