简体   繁体   English

删除(合并)SQL Server的数据库辅助数据文件

[英]Remove (merge) SQL Servers' database secondary data file

I have a database backup for which SQL Server Management Studio says that it has three files in it: an .mdf file, an .ndf file and one .ldf file. 我有一个数据库备份,SQL Server Management Studio说它有三个文件: .mdf文件, .ndf文件和一个.ldf文件。 This secondary data file (the .ndf one) was created for no obvious reason, so I want to remove it altogether (without losing data, of course), preferably during while the database is being restored from the backup. 这个辅助数据文件( .ndf one)是在没有明显原因的情况下创建的,所以我想完全删除它(当然不会丢失数据),最好是在从备份恢复数据库的过程中。

Is this at all doable? 这一切都可行吗?

Ok, found a solution. 好的,找到了解决方案。

First back up the database. 首先备份数据库。

Execute this: 执行:

USE database_name;

Then execute this, and replace logical_ndf_file_name with the logical name of your NDF file (which you can easily find out via Database->Properties_Files): 然后执行此操作,并将logical_ndf_file_name替换为NDF文件的逻辑名称(您可以通过Database-> Properties_Files轻松找到它):

DBCC SHRINKFILE('logical_ndf_file_name', EMPTYFILE);
ALTER DATABASE database_name REMOVE FILE logical_ndf_file_name;

I ran the empty followed by ndf drop during produciton load successfully. 在produciton load成功加载期间,我运行了空,然后运行了ndf drop。 I think it is important to run the drop ndf in the same transaction as the empty to ensure the database doesn't try to write to the file you are deleting, but then after an empty the database marks the files unusable, evidenced by attempting another empty shorty after. 我认为在与空相同的事务中运行drop ndf非常重要,以确保数据库不会尝试写入要删除的文件,但是在数据库空了之后,数据库会将文件标记为不可用,这可以通过尝试另一个来证明之后空虚。

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

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