Solved

cloning databases

Posted on 2007-12-06
6
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

733 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