Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL Database Creation

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-12-09 : 12:38:19
Caesar writes "Just a stupid question, but I was wondering whether it is posisble to create a database using a store procedure.
For example: I have a Master db, lets call it myMaster. Now myMaster should be able to create other databases with their own names etc. Now I want to write a store procedure that creates other databases from myMaster. Thus myMaster holds the template to create other databases with tables, store procedures etc.
Is this a viable way or is there another way.

Thanks in advance for your answer and help!

Caesar"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2001-12-09 : 13:24:10
It's even easier than this. Every new database is based on the "model" system database. Put all of the common tables, procedures, etc. you like to have in each new database in model. You can then write a generic procedure to CREATE DATABASE <newdbname> and pass a newdbname value as a parameter.

I believe you'll have to put this procedure into the "master" database and that you'll need dynamic SQL in order to have it work. Read these:

http://www.sqlteam.com/item.asp?ItemID=4599
http://www.sqlteam.com/item.asp?ItemID=4619

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2001-12-10 : 07:40:05
If you want to create the databases with internal objects you may find it easier to have a backup of the database and to perform a restore with the database name instead.

==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -