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)
 Looping Database Creation

Author  Topic 

hummy
Starting Member

32 Posts

Posted - 2006-12-18 : 10:35:22
Hi All,

I wanted to ask for a little help on creating a script that i require. I have a requirement for testing out some issues currently being experienced with some 3rd party software. To reproduce it i require to create 250 databases. I was thinking of creating 250 databases with 1 MB database and 1MB log file.

I was hoping somone would be able to help me out with creating a script to automatically create the 250 databases. I think a looped query with a counter for the databases should be ok. The database names can be incremented...such as DB_1, DB_2, DB_3 etc etc.

I'm trying to do something like that myself but having some trouble. Perhaps someone can assist me to achieve what i am wanting to do.

Thanks
Humayun

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-18 : 10:51:49

Try this in a TEST server

Declare @i int, @sql varchar(2000)
Select @i=1
While @i<=250
BEGIN
Select @sql='Create database db_'+cast(@i as varchar(3))
EXEC(@sql)
Select @i=@i+1
END


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -