Boring answer: Restore the entire database. Drop everything in the filegroups you want to get rid of. Once you have done that, remove the file groups with ALTER DATABASE.
This is the only supported way to achieve what you want.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Database uses the Recovery Model Simple. Made a partial Backup by setting some of the Filegroups Read_Only. "Backup Database mydb READ_WRITE_FILEGROUPS "
Restored the Database with partial, recovery.
Worked as expected, some of the Filegroups are online, some are "Recovery_Pending".
I want to remove / drop all objects / metadata of the "not restored" object.
I found only the possibility to "alter database mydb Remove Filegroup". The filegroup has the state defunct, but all Metadata (Schema, Tables, DatabaseFiles and so on) are still shown when you query sys.objects and so on.
This Objects will never be restored, how can i clean up the metadata of the SQL Server Database?
My main goal is to split 1 Database into multiple Databases.
Thank you for advice and help
Boring answer: Restore the entire database. Drop everything in the filegroups you want to get rid of. Once you have done that, remove the file groups with ALTER DATABASE.
This is the only supported way to achieve what you want.
Hi,
For splitting 1 database into multiple I may suggest below:
1 - You may create new database e.g. with name NewDB2 & copy tables manually tables from old to new issuing below select query:
select * into NewDB2.dbo.table1 from oldb.dbo.table1
2 - You may generate scripts for the objects you want to shift in new database.
In the instance right click on database->Tasks->Generate scripts.
You may select here objects to copy. For tables you may need to select one option in advance tab "Types of data to script" as shown in below image:
To cleanup defunct objects you take below steps:
Cleaning up metadata of defunct SQL Server objects is an important task to maintain the health and efficiency of your database. Here’s a general approach to clean up metadata for defunct SQL Server objects:
7. Check Dependencies: Ensure that no other objects depend on the ones you’ve removed. You can use the sys.dm_sql_referencing_entities
and sys.dm_sql_referenced_entities
dynamic management functions to check for dependencies.
8. Monitor Performance: After cleanup, monitor your database performance to ensure that the removals have not negatively impacted your system.
Following are commands that may helpful in this regards:
DROP TABLE [YourTableName];
DROP PROCEDURE [YourProcedureName];
DROP FUNCTION [YourFunctionName];
USE master;
GO
ALTER DATABASE [YourDatabaseName]
REMOVE FILE [YourFileName];
ALTER DATABASE [YourDatabaseName]
REMOVE FILEGROUP [YourFileGroupName];
GO
EXEC sp_updatestats;
You may go through below links before taking action:
Hi @Paolo Taverna ,
Thanks for your reaching out and welcome to Microsoft Q&A!
In addition to Erland and Zahid's answers, here is an article describing the reasons of SQL Server RECOVERY PENDING Mode, hope this can help you well!
Please refer to this official document and try to Remove Defunct Filegroups in SQL Server.
If you think the answers are helpful, please don't forget to accept it! Thanks for your understanding!
Best regards,
Lucy Chen
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
https://docs.microsoft.com/en-us/answers/support/email-notifications
Thank you very much for your answers. So far i understand there is no way to cleanup Metadata of Defunct Objects.
At this point im going the standard way. Im going to create new Databases and transfer the needed Objects from 1 Database to another.
Best Regard
Paolo