Dynamic Database Duplication

  • My apologies in advance if there's a simple soluton I've overlooked. I have a database that acts as a template of sorts that I'd like to duplicate and rename, for new customers, dynamically.

    Currently I use a stored procedure to detach the template db, copy with xp_cmdshell, then reattach under a new name.

    Previously I tried 'SELECT Table.* INTO Table IN 'Some.mdf' FROM Table'. That didn't work. The former is working, but I'd like to know if there's a better way of doing this. My thanks in advance for any ideas.

  • sounds like you've got a good solution - it's straightforward, and it works.

    Some other options:

    a) Use model as the template (trouble is you may not want EVERY new database emulating your template)

    b) use backup and restore instead of detach, copy, attach.

    c) don't have separate databases for each new customer. Have just one database and use views to segregate customers, making it appear to be a private database from their point of view - more upfront effort, but can drastically reduce maintenance.

    Cheers,

    - Mark


    Cheers,
    - Mark

  • Thanks for the comprehensive reply. I'll explore those options.

  • I know that it's more work to maintain, but I prefer to get scripts from vendors. Of course if all of the databases are on your server and not the customer's, I guess this isn't an issue.

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

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