Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dynamic Create Database file Name
Message
From
10/08/2004 13:19:32
 
 
To
10/08/2004 11:49:52
Evans Carl
System Answers Consulting, Inc
Big Lake, Minnesota, United States
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00932057
Message ID:
00932094
Views:
12
Hi Try doing it like this:

DECLARE @lcDB CHAR(512)

SET @lcDB = 'CREATE DATABASE ' + @myDBName +
' ON
( NAME = ''prods_dat'',
FILENAME = ''c:\temp\prods.mdf'',
SIZE = 4,
MAXSIZE = 10,
FILEGROWTH = 1 )'

EXEC (@lcDB)

Mace

>All
>
>I want to create a dynamic database name combining a constant with the date of creation. Is there a way I can do this in SQL?
>
>-- Get time stamp
>DECLARE @dtLogTime DATETIME
>SET @dtLogTime = GETDATE()
>DECLARE @sLogTimeString VARCHAR(50)
>declare @ArchiveName varchar(50)
>
>
>
>SET @sLogTimeString = CAST(DATEPART(month,@dtLogTime) as varchar(10)) + CAST(DATEPART(day,@dtLogTime) as varchar(10))+ CAST(DATEPART(year,@dtLogTime) as varchar(10))
>
>set @ArchiveName ='SRCCTranslog'+@sLogTimeString
>select @ArchiveName
>
>SRCCTranslog8102004
>
>-- Create the Archive Database
>USE master
>GO
>
>CREATE DATABASE @ArchiveName
>ON
>( NAME = SRCCTrans_dat,
> FILENAME = 'c:\program files\microsoft sql server\mssql\data\SRCCTrans_dat.mdf',
> SIZE = 10,
> MAXSIZE = 50,
> FILEGROWTH = 5 )
>LOG ON
>( NAME = 'SRCCTrans_log',
> FILENAME = 'c:\program files\microsoft sql server\mssql\data\SRCCTrans_log.ldf',
> SIZE = 3MB,
> MAXSIZE = 3MB,
> FILEGROWTH = 3MB )
>GO
>
>I get an error of course - Can this be done?
>
>Evans
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform