General information
Forum:
Microsoft SQL Server
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
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only