简体   繁体   English

如果从机器上删除了 .mdf 和 .ldf 文件,如何从 SQL Server 中删除数据库?

[英]How to delete database from SQL Server if .mdf and .ldf file is removed from the machine?

I have restore database into SQL Server as WMDATA.我已将数据库作为 WMDATA 还原到 SQL Server。

One day my friend using my machine and removed .mdf and .ldf file for WMDATA.有一天,我的朋友使用我的机器删除了 WMDATA 的.mdf.ldf文件。

Now I want to remove WMDATA database from my SQL Server but it gives me error for .mdf and .ldf file.现在我想从我的 SQL Server 中删除WMDATA数据库,但它给了我.mdf.ldf文件的错误。

DROP DATABASE WMDATA should work, because it will drop a database even if it is suspect . DROP DATABASE WMDATA应该可以工作,因为即使它是可疑的,它也会删除数据库

If that doesn't help, you should add some more useful information: what version of MSSQL;如果这没有帮助,您应该添加一些更有用的信息:MSSQL 的版本; how are you dropping the database;你是如何删除数据库的; what is the error message etc. You might also get a better answer on the DBA or Server Fault sites.什么是错误消息等。您可能还会在DBAServer Fault站点上获得更好的答案。

I run into this issue as well, while trying to delete some localdb databases through SSMS and DROP DATABASE didn't work for me.我也遇到了这个问题,同时尝试通过 SSMS 和DROP DATABASE删除一些 localdb 数据库对我不起作用。 However, I found that it is possible to "recreate" the database after an unsuccessful deletion.但是,我发现在删除失败后可以“重新创建”数据库。 I did the following:我做了以下事情:

  1. Delete the database, get error that .mdf files are missing.删除数据库,得到 .mdf 文件丢失的错误。
  2. Create new database with the same name.创建同名的新数据库。
  3. Delete the database again, this time without errors.再次删除数据库,这次没有错误。

PS: If you don't do step 1, you get an error in step 2 that a database with that name already exists. PS:如果不执行步骤 1,则在步骤 2 中会出现具有该名称的数据库已存在的错误。

Right click on the DB > Delete右键单击数据库 > 删除

Uncheck "Delete backup and restore history information for databases" Check "Close existing connections"取消选中“删除数据库的备份和还原历史信息”选中“关闭现有连接”

And hit OK.并点击确定。

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

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