• There isn't a built-in way to do it but you do have choices.

    You can go with SMO which has a script method, but SMO has always been a little hard to swallow for me.

    You can go with something like VSTE for DBAs. The MSBuild commandline has an option for scripting and that can be scripted and probably run from a job.

    Or you can use my favorite method of Powershell. Powershell can script DBs very easily with very little effort.

    I've actually made a video on this very topic. I don't really teach you how to turn it into a job, but it's a first step and I hope to complete another video showing you how to automate it very soon.

    Anyway, watch it and see if it'll get you what you want because other than going with a 3rd party option, it's really your best bet.

    http://midnightdba.itbookworm.com/PowershellScriptDBObjects/PowershellScriptDBObjects.html">

    http://midnightdba.itbookworm.com/PowershellScriptDBObjects/PowershellScriptDBObjects.html

    And while you're at it, I've got a Powershell basics video as well. It'll give you a quick overview of how PS works.

    http://midnightdba.itbookworm.com/PowerShellOverview/PowerShellOverview.html">

    http://midnightdba.itbookworm.com/PowerShellOverview/PowerShellOverview.html

    Watch my free SQL Server Tutorials at:
    http://MidnightDBA.com
    Blog Author of:
    DBA Rant – http://www.MidnightDBA.com/DBARant

    Minion Maintenance is FREE: