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 脚本
基础教程推荐
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
