@Database是須要備份的數據庫名,@Path是備份目錄注意最後一個"/"sql
use master go declare @Database nvarchar(256),@Path nvarchar(2048) select @Database=N'AdventureWorks',@Path=N'D:/TDDOWNLOAD/' declare @sql nvarchar(max) select @sql =N'BACKUP DATABASE '+@Database+N' TO DISK = '''+@Path+@Database+N'_Full_'+REPLACE(REPLACE(REPLACE(convert(nvarchar(30),getdate(),126),'-','_'),':','_'),'.','_')+N'.bak'' WITH NOFORMAT, INIT, NAME = N''Full Database Backup'', SKIP' exec (@sql) go
最後生成的備份文件數據庫
AdventureWorks_Full_2010_07_08T15_14_53_750.bak.net