我想在不使用管理工作室的情况下在sql server中附加我的数据库怎么做? 请帮助
由于
答案 0 :(得分:2)
Syntax of Query for attach
sp_attach_db [ @dbname= ] 'dbname'
, [ @filename1= ] 'filename_n' [ ,...16 ]
例如:
EXEC sp_attach_db @dbname = N'AdventureWorks2012',
@filename1 =
N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data\AdventureWorks2012_Data.mdf',
@filename2 =
N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data\AdventureWorks2012_log.ldf';
查询分离的语法
sp_detach_db [ @dbname= ] 'database_name'
[ , [ @skipchecks= ] 'skipchecks' ]
[ , [ @keepfulltextindexfile = ] 'KeepFulltextIndexFile' ]
例如:
exec sp_detach_db @dbname='AdventureWorks2012'
, @keepfulltextindexfile='true';
答案 1 :(得分:2)
sqlcmd -S Server\Instance
USE [master]
GO
CREATE DATABASE databasename ON
( FILENAME = N'path\databasename.mdf' ),
( FILENAME = N'path\databasename.ldf' )
FOR ATTACH ;
GO
答案 2 :(得分:1)
取决于什么版本的SQL Server,但是您可以使用SQLCMD的最新版本是从cmd行执行的。参见像
这样的问题How to attach a SQL Server database from the command line
参考TechNet