简体   繁体   English

将断开连接的sql数据库导入新的sql数据库

[英]import disconnected sql database into new sql database

I had a virus on my machine, and I had to have it rebuilt, I saved the SQL Server mdf file before have the computer rebuilt. 我的计算机上感染了病毒,因此必须对其进行重建,然后在重建计算机之前保存了SQL Server mdf文件。 not that it was rebuilt I tried to import the database using 不是它被重建,我试图使用导入数据库

CREATE DATABASE [Invoice] 
ON PRIMARY (FILENAME = N' WHATEVER PATH THE FILE IS ')
FOR ATTACH_REBUILD_LOG 
GO

That didn't I did some research I tried to use 那不是我做过的一些尝试

sp_attach_single_file_db @dbname=Invoices, @physname 'path of Database'

That however didn't work either. 但是那也不起作用。

So after researching the error I found out that because the database wasn't closed out and I found out that I cannot import that I want to try to import the data into a new database that I've created. 因此,在研究了错误之后,我发现由于没有关闭数据库,并且发现无法导入,因此我想尝试将数据导入到我创建的新数据库中。

I do not have any tables in the new database but I would like to import all the tables and data from [dbo].[Invoices] in new database. 我在新数据库中没有任何表,但是我想从新数据库中的[dbo].[Invoices]导入所有表和数据。 How can I do this? 我怎样才能做到这一点?

I have a suggestion which has worked for me in the past, but I cant guarantee it will work for you. 我有一个过去对我有用的建议,但我不能保证它会对您有用。

Create a new blank database. 创建一个新的空白数据库。 Take the new database offline or stop sql server. 使新数据库脱机或停止sql server。 Replace the new database MDF file with the old database MDF file. 用旧的数据库MDF文件替换新的数据库MDF文件。 Remove any log file from the newly created database. 从新创建的数据库中删除任何日志文件。 Try to start sql server. 尝试启动sql server。 See if the database can be accessed. 查看是否可以访问数据库。

Again, I can't guarantee this will work, but definitely worth a try if you are in a bind. 同样,我不能保证这会起作用,但是如果您处于绑定状态,绝对值得一试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM