如何从命令行附加SQL Server数据库 [英] How to attach a SQL Server database from the command line

查看:535
本文介绍了如何从命令行附加SQL Server数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以输入命令行命令(如在批处理文件中)将分离的数据库附加到SQL Server,而不是打开管理工作室并在其中执行?

Is it possible to enter a command line command (like in a batch file) to attach a detached database to SQL Server, in stead of opening the management studio and doing it in there?

推荐答案

您需要使用: sqlcmd实用程序


sqlcmd实用程序允许您输入
Transact-SQL语句,系统
程序和脚本文件在
命令提示符下,在
SQLCMD模式下的查询编辑器中,在Windows脚本文件
中或在操作系统(Cmd.exe)
作业步骤的SQL Server代理作业。
此实用程序使用OLE DB执行
Transact-SQL批处理。

The sqlcmd utility lets you enter Transact-SQL statements, system procedures, and script files at the command prompt, in Query Editor in SQLCMD mode, in a Windows script file or in an operating system (Cmd.exe) job step of a SQL Server Agent job. This utility uses OLE DB to execute Transact-SQL batches.

然后使用 CREATE DATABASE(Transact-SQL)执行attach和 sp_detach_db(Transact-SQL)来执行分离。 sp_attach_db(Transact-SQL)将在未来版本的Microsoft SQL Server。

Then use CREATE DATABASE (Transact-SQL) to do the attach and sp_detach_db (Transact-SQL) to do the detach. The sp_attach_db (Transact-SQL) is going to be removed in a future version of Microsoft SQL Server.

这篇关于如何从命令行附加SQL Server数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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