脚本:

use master;
go
---声明变量
declare @dbName nvarchar(max)='MG_DATA';
declare @dbFullName nvarchar(max)='C:\Backup\MG_DATA_'+ convert(varchar(50),getdate(),112) +'_'+ DateName(hour,GetDate())+DateName(minute,GetDate()) +DateName(second,GetDate())+'.bak';
---备份数据库
DECLARE @kid varchar(100)
SET @kid=''
SELECT @kid= @kid + 'KILL '+CAST(spid as Varchar(10)) FROM master..sysprocesses
WHERE dbid=DB_ID(@dbName)
PRINT @kid
EXEC(@kid);
backup database MG_DATA to disk=@dbFullName; 步骤:1.新建作业

SQL Server 自动备份数据脚本-LMLPHP

2.

SQL Server 自动备份数据脚本-LMLPHP

SQL Server 自动备份数据脚本-LMLPHP

https://blog.csdn.net/u011127019/article/details/54141117

05-08 15:08