From: bob123 on
Hi,

I have the small T-SQL script below to backup my databases:

Here is a snippet:
BACKUP DATABASE [model] TO DISK =
N'G:\SAVE\SQLSRV\MSSQL10.MSSQLSERVER\MSSQL\Backup\model\model_backup_2010_07_05_212931.bak'
WITH NOFORMAT, NOINIT, NAME = N'model_backup_2010_07_05_212931', SKIP,
REWIND, NOUNLOAD, STATS = 10

how to get timestamp automatically generated on execution ?

Thanks in advance




From: Dan Guzman on
> how to get timestamp automatically generated on execution ?

You can build the desired filename in a variable for use in the BACKUP
command:

DECLARE @BackupFilePath varchar(255);

SET @BackupFilePath =
N'G:\SAVE\SQLSRV\MSSQL10.MSSQLSERVER\MSSQL\Backup\model\model_backup_'
+ REPLACE(CONVERT(varchar(19), GETDATE(), 121), ':', '');

BACKUP DATABASE model TO
DISK = @BackupFilePath
....

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

"bob123" <bob123(a)gmail.com> wrote in message
news:4c3237c2$0$436$426a74cc(a)news.free.fr...
> Hi,
>
> I have the small T-SQL script below to backup my databases:
>
> Here is a snippet:
> BACKUP DATABASE [model] TO DISK =
> N'G:\SAVE\SQLSRV\MSSQL10.MSSQLSERVER\MSSQL\Backup\model\model_backup_2010_07_05_212931.bak'
> WITH NOFORMAT, NOINIT, NAME = N'model_backup_2010_07_05_212931', SKIP,
> REWIND, NOUNLOAD, STATS = 10
>
> how to get timestamp automatically generated on execution ?
>
> Thanks in advance
>
>
>
>
From: bob123 on
OK thanks

"Dan Guzman" <guzmanda(a)nospam-online.sbcglobal.net> a �crit dans le message
de news: eYPEs4HHLHA.3352(a)TK2MSFTNGP05.phx.gbl...
>> how to get timestamp automatically generated on execution ?
>
> You can build the desired filename in a variable for use in the BACKUP
> command:
>
> DECLARE @BackupFilePath varchar(255);
>
> SET @BackupFilePath =
> N'G:\SAVE\SQLSRV\MSSQL10.MSSQLSERVER\MSSQL\Backup\model\model_backup_'
> + REPLACE(CONVERT(varchar(19), GETDATE(), 121), ':', '');
>
> BACKUP DATABASE model TO
> DISK = @BackupFilePath
> ...
>
> --
> Hope this helps.
>
> Dan Guzman
> SQL Server MVP
> http://weblogs.sqlteam.com/dang/
>
> "bob123" <bob123(a)gmail.com> wrote in message
> news:4c3237c2$0$436$426a74cc(a)news.free.fr...
>> Hi,
>>
>> I have the small T-SQL script below to backup my databases:
>>
>> Here is a snippet:
>> BACKUP DATABASE [model] TO DISK =
>> N'G:\SAVE\SQLSRV\MSSQL10.MSSQLSERVER\MSSQL\Backup\model\model_backup_2010_07_05_212931.bak'
>> WITH NOFORMAT, NOINIT, NAME = N'model_backup_2010_07_05_212931', SKIP,
>> REWIND, NOUNLOAD, STATS = 10
>>
>> how to get timestamp automatically generated on execution ?
>>
>> Thanks in advance
>>
>>
>>
>>