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 脚本
基础教程推荐
- 在 SQL 中连接多个表 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 无法解决整理冲突 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
