本文介绍了如何使用Sql语句备份数据库为.Bak文件在硬盘上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要备份数据库为.bak文件,我想要硬盘上的文件我使用此代码n输出是succsefull但我没有在路径上找到任何文件:
使用try2
i want to do backup for database as .bak file where i want the file on hard disk i used this code n the output is succsefull but i didnt find any file on the path:
use try2
DECLARE @name VARCHAR(50) -- database name
DECLARE @path VARCHAR(256) -- path for backup files
DECLARE @fileName VARCHAR(256) -- filename for backup
DECLARE @fileDate VARCHAR(20) -- used for file name
-- specify database backup directory
SET @path = 'd:\Backup\'
set @name='try2'
-- specify filename format
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) + '_' + REPLACE(CONVERT(VARCHAR(20),GETDATE(),108),':','')
SET @fileName = @path + @name + '_' + @fileDate + '.BAK'
BACKUP DATABASE @name TO DISK = @fileName --WITH RETAINDAYS = 30, NOFORMAT, NOINIT, SKIP, NOREWIND, NOUNLOAD, STATS = 10
-
结果是
--
the result is
Processed 304 pages for database 'try2', file 'Council_Ministers_Meetings' on file 1.
Processed 1 pages for database 'try2', file 'Council_Ministers_Meetings_log' on file 1.
BACKUP DATABASE successfully processed 305 pages in 0.344 seconds (6.926 MB/sec).
注意:Council_Ministers_Meetings是我没有使用的数据库名称我想为try2数据库做备份
note : Council_Ministers_Meetings is database name i didnt use where i want to do backup for try2 database
推荐答案
这篇关于如何使用Sql语句备份数据库为.Bak文件在硬盘上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!