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.
| Author |
Topic |
|
pcoates
Starting Member
2 Posts |
Posted - 2010-05-04 : 18:08:00
|
| Hello,I have been tasked w/creating 500 sql server DBs, and I am not familiar w/scripting w/loops but I absolutely dread creating a file w/500 'create database' statements. Here is what I have so far, but the syntax of the 'create database' statement is wrong. Can/will someone help - please?!? Thanks in advance. PcoatesDECLARE @str VARCHAR(10)DECLARE @index INTSET @str = 'DB'SET @index = 000WHILE @index < 500BEGIN create database @str@index set @index = @index + 1END |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2010-05-04 : 18:18:00
|
| [code]DECLARE @str VARCHAR(10)DECLARE @index INTDECLARE @SQL VARCHAR(100)SET @str = 'DB'SET @index = 0WHILE @index < 500BEGIN SET @SQL = 'create database ' + @str + CASE WHEN @index < 10 THEN '00' WHEN @index < 100 THEN '0' ELSE '' END + CAST(@index as VARCHAR) EXEC(@SQL) set @index = @index + 1END[/code]------------------------------------------------------------------------------------Any and all code contained within this post comes with a 100% money back guarantee. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
pcoates
Starting Member
2 Posts |
Posted - 2010-05-05 : 00:10:58
|
| Awesome! Thanks a million DBA in the making!! THe DBs will be very small and spread across multiple instances. I am performing hardware load/performance testing and have 500 DBs as my benchmark. Thanks again! |
 |
|
|
|
|
|