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 |
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2004-01-12 : 21:37:57
|
Hi ChampsGot a customer who wants to script his database creation (lots of little ones) ideally based on parameters.The database creation command doesn't appear to like variables, and so this would appear to be a problem. EgCREATE DATABASE @DBNameON ( NAME = @DBName + '_dat', FILENAME = @DBFile, SIZE = @DBSize)LOG ON( NAME = @DNName + '_log', FILENAME = @DBLog, SIZE = @DBSize)GO Is there any way I can do this?(be gentle with me, I'm not used to the big, scary admin forum)--I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2004-01-12 : 22:03:00
|
| You could use dynamic SQL for this.Declare @sql nvarchar(4000), @dbname nvarchar(50), @dbfile nvarchar(50), @dblog nvarchar(50), @dbsize intSELECT @dbname = 'DynamicTest', @dbfile = 'foo', @dblog = 'foo', @DBsize = 10SELECT @sql = 'CREATE DATABASE ' + @DBName + 'ON ( NAME = ' + @DBName + '_dat, FILENAME = ' + @DBFile + ', SIZE = ' + Cast(@DBSize as nvarchar(10)) + ')LOG ON( NAME = ' + @DBName + '_log , FILENAME = ' + @DBLog + ', SIZE = ' + Cast(@DBSize as nvarchar(10)) + ')'Execute( @sql )Damian |
 |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2004-01-12 : 22:16:39
|
There once was a Yak from SAWho was scared of posting as DBAHe needed a scriptletThat wasn't explicitAnd dynamic sql saved the day Damian |
 |
|
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2004-01-12 : 22:23:21
|
| TouchéNo really Damian, that really was grand - both responses!A Yak from Newtown in the eastOffered free help to all, man and beastalthough they were tentativehe was not argumentativebut gracious even unto the least....--I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
|
|
|
|
|
|