Deleting files and folders (backup) when Database does not exist no more

  • Hello Gentlemen,

    I need a liitle help with this one,   I have a live database and of course a folder on a specific drive with the backups,  When i delete the database i would also like to delete the files and folders associated with that database.  SO some sort of a job that check if the database exist or not and deletes the file and folders when the database is no longer there...is it possible to do ?

  • hillcat - Wednesday, February 14, 2018 1:18 PM

    Hello Gentlemen,

    I need a liitle help with this one,   I have a live database and of course a folder on a specific drive with the backups,  When i delete the database i would also like to delete the files and folders associated with that database.  SO some sort of a job that check if the database exist or not and deletes the file and folders when the database is no longer there...is it possible to do ?

    Download Ola Hallengren's free and awesome maintenance suite (hopefully you are already using it!!) and look in there at the code he uses to delete old backups. Use that as your starting point for a script to do what you want.

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

  • hillcat - Wednesday, February 14, 2018 1:18 PM

    Hello Gentlemen,

    I need a liitle help with this one,   I have a live database and of course a folder on a specific drive with the backups,  When i delete the database i would also like to delete the files and folders associated with that database.  SO some sort of a job that check if the database exist or not and deletes the file and folders when the database is no longer there...is it possible to do ?

    If the database is no longer there, how can we know the related data/log files and their location(s)? If some specific folders are only for data/log file, you probably need to compare file list with master_files to find out the ones you need to delete. BTW, Ola Hallengren's solution does includes much necessary tech skills, but it might be not so easy to get what you need in short time.

    GASQL.com - Focus on Database and Cloud

  • This was removed by the editor as SPAM

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply