简单的SQL Server备份脚本代码
编程学习 2021-07-05 13:42www.dzhlxh.cn编程入门
一般的情况下我们会选用SQL Server自带的数据库维护计划来定义备份.
但有些时候,有的机器数据库维护计划不能成功实现备份.
错误原因可能不尽相同, 这时我们可以用简单的SQL Server备份脚本来做备份.
生成简单的SQL Server备份脚本的SQL语句:
use master
select 'backup database '+name+' to disk=''F:\sqlserver_backup\'+name+'.bak'' with init' from sysdatabases
-------------------------------------------------------------------------------------------------
backup database master to disk='F:\sqlserver_backup\master.bak' with init
backup database model to disk='F:\sqlserver_backup\model.bak' with init
backup database msdb to disk='F:\sqlserver_backup\msdb.bak' with init
backup database db_app1 to disk='F:\sqlserver_backup\db_app1.bak' with init
backup database db_app2 to disk=F:\sqlserver_backup\db_app2.bak' with init
但有些时候,有的机器数据库维护计划不能成功实现备份.
错误原因可能不尽相同, 这时我们可以用简单的SQL Server备份脚本来做备份.
生成简单的SQL Server备份脚本的SQL语句:
use master
select 'backup database '+name+' to disk=''F:\sqlserver_backup\'+name+'.bak'' with init' from sysdatabases
-------------------------------------------------------------------------------------------------
backup database master to disk='F:\sqlserver_backup\master.bak' with init
backup database model to disk='F:\sqlserver_backup\model.bak' with init
backup database msdb to disk='F:\sqlserver_backup\msdb.bak' with init
backup database db_app1 to disk='F:\sqlserver_backup\db_app1.bak' with init
backup database db_app2 to disk=F:\sqlserver_backup\db_app2.bak' with init
上一篇:sql基本函数大全
下一篇:SQL SERVER的优化建议与方法