Created
June 25, 2016 12:03
-
-
Save BrentOzar/5dcebc37adafa2c7142c585e0837820a to your computer and use it in GitHub Desktop.
Create a bunch of databases in a loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @StringTemplate VARCHAR(1000); | |
DECLARE @StringToExecute VARCHAR(1000); | |
DECLARE @Counter TINYINT = 1; | |
SET @StringTemplate = 'CREATE DATABASE [ConsumeMassQuantities##REPLACE##] | |
CONTAINMENT = NONE | |
ON PRIMARY | |
( NAME = N''ConsumeMassQuantities'', FILENAME = N''D:\MSSQL\Data\ConsumeMassQuantities##REPLACE##.mdf'' , SIZE = 8192KB , FILEGROWTH = 65536KB ) | |
LOG ON | |
( NAME = N''ConsumeMassQuantities_log'', FILENAME = N''D:\MSSQL\Data\ConsumeMassQuantities##REPLACE##_log.ldf'' , SIZE = 8192KB , FILEGROWTH = 65536KB )' | |
WHILE @Counter < 100 | |
BEGIN | |
SET @StringToExecute = REPLACE(@StringTemplate, '##REPLACE##', @Counter) | |
EXEC (@StringToExecute); | |
SET @Counter = @Counter + 1; | |
END | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment