EXEC sp_attach_db @dbname = 'zjJunHaoCarChain', @filename1 = 'D:\sql\zjJunHaoCarChain.mdf', @filename2 = 'D:\sql\zjJunHaoCarChain_log.ldf'
或者:
该方法只针对同等级数据库,不能跨级 比如sqlserver2012还原到sqlserver2008会报错
用数据库日志文件对数据库进行还原
一 将日志文件.mdf文件和.ldf文件copy放置在sqlserver安装目录的DATA文件夹下
二在数据库中运行下面语句
USE master;
CREATE DATABASE 数据库名
ON(FILENAME='复制后.mdf文件路径'),
(FILENAME='复制后.ldf文件路径')
FOR ATTACH;
GO
USE master; GO CREATE DATABASE Test ON (FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Test.mdf'), (FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Test.ldf') FOR ATTACH; GO