Solved

cloning databases

Posted on 2007-12-06
6
149 Views
Last Modified: 2011-09-20
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
Comment
Question by:picsnet
  • 4
  • 2
6 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 20421331
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
 
LVL 1

Author Comment

by:picsnet
ID: 20421417
i know how to do it that way, but for this app.... i want this kind of architecture...  
0
 
LVL 21

Accepted Solution

by:
surajguptha earned 500 total points
ID: 20421536
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 1

Author Comment

by:picsnet
ID: 20421631
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
 
LVL 1

Author Comment

by:picsnet
ID: 20421875
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
 
LVL 1

Author Comment

by:picsnet
ID: 20421879
forgot the code

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

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now