Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dynamic Create Database file Name
Message
De
10/08/2004 15:30:23
Evans Carl
System Answers Consulting, Inc
Big Lake, Minnesota, États-Unis
 
 
À
10/08/2004 13:19:32
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00932057
Message ID:
00932169
Vues:
15
>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

Macer,

I feel like Duh because I use literal string SQL statement build ups quite a few times. But thanks for pointing me in the right direction.


Evans
¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø,¸¸,ø¤º°`°º¤ø¤º°¤º°`°º¤ø¤º°¤º°
Carl Evans
CEO & President
System Answers Consulting, Inc.
MCSD .NET, ASP.NET, C#.NET, VB.NET,
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform