100 SQL Databases

Hello,
Can someone show me the TSQL I need to write in order to create 100 SQL databases in one go.
I want them to be called DB1, DB2, DB3, DB4...etc etc

I know how to create one database;
---------------------------------------------------
USE MASTER
GO
CREATE DATABASE DB1
ON PRIMARY
(
NAME = DB1_dat,
FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\DB1.mdf',
SIZE=4,
MAXSIZE=10,
FILEGROWTH=1
)
-------------------------
But I don't want to do this 100 times,

Thanks in advance
ICW


Answer this question

100 SQL Databases

  • Worren

    Thanks for the tip. I'm not really sure where to start, I am a bit of a newbie i'm afraid. Any clues

    Much appreciated

    Thanks


  • Jeff Beehler

    Thanks I will give it a go.

    regards

    icw


  • Ak5intoe

    You can start with the following topic in SQL Server 2005.


  • sgtpazo

    You will have to use dynamic SQL to execute the parameterized CREATE DATABASE statement in a WHILE loop. Search in Books Online for dynamic SQL execution. You have to parameterize the name fo the DB, logical file names and database file names.

  • 100 SQL Databases