--如果xp_cmdshell沒有啓用,請先啓用
sp_configure 'show advanced options',1
reconfigure
go
sp_configure 'xp_cmdshell',1
reconfigure
go
--1.先創建映射
exec master..xp_cmdshell 'net use \\192.168.20.10\backup 密碼 /user:192.168.1.251\administrator'
--2.利用映射備份數據庫
backup database TXDB to disk='\\192.168.20.10\backup\TXDB.bak'
--3.刪除映射
exec master..xp_cmdshell 'net use \\192.168.20.10\backup /delete'
--xp_cmdshell關閉
sp_configure 'show advanced options',1
reconfigure
go
sp_configure 'xp_cmdshell',0
reconfigure
go