Solved

cloning databases

Posted on 2007-12-06
6
148 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

706 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

21 Experts available now in Live!

Get 1:1 Help Now