Created
November 1, 2012 09:37
-
-
Save ichiroku11/3992735 to your computer and use it in GitHub Desktop.
指定DBを指定フォルダにバックアップするクエリ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
指定DBを指定フォルダにバックアップ | |
バックアップファイル名には日付の文字列が含まれる | |
*/ | |
declare @dbName sysname = N'DB名'; | |
declare @folder nvarchar( max ) = N'バックアップフォルダ(\で終わる必要あり)'; | |
declare @date datetime = getdate(); | |
declare @ymd char( 8 ) = convert( char( 8 ), @date, 112 ); -- yymmdd | |
declare @hms char( 6 ) = replace( convert( char( 8 ), @date, 108 ), ':', '' ); -- hh:mm:ss -> hhmmss | |
declare @file nvarchar( max ) = @folder + @dbName + N'_' + @ymd + @hms + N'_full.bak'; | |
select @file; | |
backup database @dbName to disk = @file; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment