September 21, 2020 at 4:24 pm
Comments posted to this topic are about the item Searching for orphaned DB files on the SQL server
M.T.
September 21, 2020 at 7:11 pm
Any MDF, NDF, or LDF file currently being used by SQL Server cannot be modified in any way. With that in mind (and it would also work if multiple instances had files in a given directory), why not just tell the system to rename them all with a (for example), "NU_" prefix skipping the ones that cannot be renamed? Then, to find all the files that could be moved to an archive or deleted or whatever, just do a DIR "NU_*.*" in the directory and you'll have your list. Same could be done with a Move or Delete command.
The REN command is self-recursive and doesn't stop when it finds a file that is currently in use. For example...
REN *.MDF NU_*.MDF
Only the inactive files will be renamed, if any.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 21, 2020 at 7:22 pm
Jeff, you would be right but if DB is OFFLINE, you are able e.g. delete db file. I am pretty sure you would be able to rename files from other instance if some DB is offline.
M.T.
September 21, 2020 at 10:41 pm
Yes, offline database data files can be deleted, I believe that's the top 1 reason why a data file was orphaned, drop an offline database will leave the data files around.
September 22, 2020 at 12:55 am
True enough. Thanks for the feedback.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply