1、把mdf文件和ldf文件拷贝到数据库的默认路径C:Program FilesMicrosoft SQL ServerMSSQL10.MSSQLSERVERMSSQLDATA里;
2、在sqlserver里新建个查询,执行下面代码;
USE master; GO CREATE DATABASE NewFile ON (FILENAME = 'C:Program FilesMicrosoft SQL ServerMSSQL10.MSSQLSERVERMSSQLDATAFile.mdf'), (FILENAME = 'C:Program FilesMicrosoft SQL ServerMSSQL10.MSSQLSERVERMSSQLDATAFile_log.ldf') FOR ATTACH; GO
3、刷新数据库,就出现了新的数据库NewFile;
根据mdf文件和ldf文件还原成功!