• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

cloning databases

Has anyone ever wrote an app where they keep each company in a seperate database, and there is also a master database... and when you create a new company, it automatically clones a starter database and names it the name they wanted, etc...  

I've never did anything like this... I was hoping someone could tell me the best way to do it, and the best way to apply changes.   Like if you want to change one stored procedure, then change it for all the children at once.  

I have some ideas on how to do it, but they seem like a decent amount of work to me... Maybe someone else has it down pat already...

Any code is appreciated...
0
picsnet
Asked:
picsnet
  • 4
  • 2
1 Solution
 
surajgupthaCommented:
we use it this way
I have a company table containing 1,2,3,4 companies
and each table in the database has a company_id column indicating which company the row is for....

This way there is no need to create new databases, rather you could just have the same table for multiple companies...
0
 
picsnetAuthor Commented:
i know how to do it that way, but for this app.... i want this kind of architecture...  
0
 
surajgupthaCommented:
As far as i know.....
Clone Table/ Databases for a SQL Server seems to be a product. Like this one
http://www.ombelt.com/clone/mssql/index.html
If you can get your hands on the source code of such a product or use it as a command line utility you can achieve the same
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
picsnetAuthor Commented:
it is actually very simple....  i was just googling it... you create what you want your database to look like in the model database, and then everytime you create a database, then it will have everything that model has...

now the only thing i have to do is find a simple way to loop through the databases to create a new stored procedure or alter another procedure........

0
 
picsnetAuthor Commented:
and here is the other answer... prefix your databases with something, and then search for the prefix...  the only thing that sucks is that if you make a change to a stored proc... you have to write the whole thing out in dynamic sql to do this method...

It'd be nice to be able to make a change to model and then have a loop that tells every other database to grab the change from model, but i don't know if this is possible
0
 
picsnetAuthor Commented:
forgot the code

EXEC sp_MSForEachDB
 
'USE ? Select Db_Name()
      If Db_Name() = ''BevolutionMaster''
            Begin
                  Select * From Company
            End'
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now