SqlAgent備份腳本

declare @dbname varchar(255)
declare @back_path varchar(255)
set @dbname='emcp'
set @back_path= 'e:\'+@dbname+'\'+@dbname
    +convert(varchar(9),getdate(),112)
    +CAST(datepart(hour,getdate()) as char(2))
    +CAST(datepart(minute,getdate()) as char(2))
    +CAST(datepart(second,getdate()) as CHAR(2))
    +'.bak'

exec('use ['+@dbname+']')
exec('backup database ['+@dbname+'] to disk='''+@back_path+'''')
相關文章
相關標籤/搜索