• Nero-1119276 (10/29/2009)


    If i write this code

    backup database to disk='Path'

    Now what should i use to include date in backup name likewise

    testbackup01-01-2009.bck

    You’ll have to use the date and time as a part the file’s name so the names will be unique and you’ll know when the backup was taken. One option to do it is to write the backup statement as dynamic SQL and then use a combination of string manipulating and getdate() functions in order to get the file’s name. Another option that is not widely known is to use the Agent’s tokens. If you’ll use this option, you won’t have to use dynamic SQL and the agent will convert the tokens with the real value. You can read about the SQL Agent tokens here – http://www.sqldev.net/sqlagent/SQLAgentStepTokens.htm%5B/url%5D.

    Personally I’d use the maintenance wizard for that instead of writing it on my own. Any reason that you are not using it?

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/