Creating multiple copies of a SQL Database

  • Hi there!

    Is there a (simple) way to replicate an entire database (SQL Server 2000) in code (T-SQL/Stored procedure) and populate it with data. The database would have to be renamed each time this was done.

    The scenario is a hosted package where companies are given a specific key which access a particluar database on the server. Each company will have their own database in case at a later date they wish to move it elsewhere etc,

    Thanks in advance

    Dave

  • I guess one way would be to restore the original database to a database with a new name.

    You can do this in TSQL statements (I'm not sure of them off the top of my head but I'm sure it is in BOL).

    Jeremy

  • Backup and restore is the best way. If it's a template db, this is easy to script in T-SQL.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

    The Best of SQL Server Central.com 2002 - http://www.sqlservercentral.com/bestof/

    http://www.dkranch.net

  • The MODEL database can be a solution.

    Create all procedures and tables on it.

    All new created databases will have all tables and SPs

    If tables are populated in model they will be populated in the new db too.

    Larry

  • Thanks for the suggestions guys.

    I'd created a script file that seems to work using the Wizard in SQL Server. It creates all the tables, inner joins, Sps etc. I was thinking of putting it into a stored procedure with parameters I'll pass in to change the name of the database. The idea is that I can create a database remotely on a server, create a key that has the path for the database and its name, then assign the key to the customer.

    Does this sound OK or am I overcomplicating things!

    Thanks

    Dave

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

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