Who can explain list of xp_Delete_file
parameters in sql server. I don't find msdn document for this stored procedure.
谁能解释SQL SERVER中的XP_Delete_FILE参数列表。我找不到此存储过程的MSDN文档。
I got script of xp_Delete_file from maintenance plan but didn't understand first parameter.
我从维护计划中得到了XP_Delete_FILE的脚本,但不理解第一个参数。
更多回答
@BogdanSahlean. OK. not exists any document in msdn. but no one know parameters and usage of these. and not exists any document in non Microsoft reference.
@BogdanSahlean。好的。MSDN中不存在任何文档。但没有人知道它们的参数和用法。并且在非Microsoft参考中不存在任何文档。
优秀答案推荐
xp_delete_file
take five parameters:
xp_delete_file有五个参数:
- File Type = 0 for backup files or 1 for report files.
- Folder Path = The folder to delete files. The path must end with a backslash "".
- File Extension = This could be 'BAK' or 'TRN' or whatever you normally use.
- Date = The cutoff date for what files need to be deleted.
- Subfolder = 0 to ignore subfolders, 1 to delete files in
subfolders.
Source How to Use xp_delete_file to Purge Old Backup Files
by Patrick Keisler
来源:如何使用XP_DELETE_FILE清除旧备份文件
Following on from the comment above, I have been testing this on SQL Server 2012 SP4 and I can confirm the syntax EXEC master.dbo.xp_delete_file 0, 'C:\Some Path\Backup file.bak' works and deletes the specific named file.
在上面的评论之后,我一直在SQL Server 2012 SP4上测试这一点,我可以确认语法exec master.dbo.xp_ete_file 0,‘C:\Some Path\Backup File.bak’起作用并删除特定的命名文件。
I found this to be more obvious, since I like showing parameters:
我发现这一点更明显,因为我喜欢显示参数:
DECLARE @DeleteDate DATETIME = DATEADD(wk,-2,GETDATE());
DECLARE @ReturnVal int
EXEC @ReturnVal = master.dbo.xp_delete_file
@FileType = 0,
@FolderPath = N'U:\SQLBackups',
@FileExtension = N'bak',
@Date = @DeleteDate,
@Subfolder = 1
print @ReturnVal
Note the following extra information (tested on SQL Server 2019 in a Microsoft Windows environment... I can't speak for other OSs):
请注意以下额外信息(在Microsoft Windows环境中的SQL Server 2019上进行了测试...我不能代表其他操作系统发言):
- the
@Date
parameter can include a time component;
- it is accurate to at least 1 second (I haven't tested milliseconds), suggesting the parameter is of type
datetime
(at least);
- the SP uses the Date Modified OS property (not the Date Created).
更多回答
In SQL Server 2014 at least, the second parameter (Folder Path) can be a specific filename, which results in only that one file being removed, e.g.: EXEC master.dbo.xp_delete_file 0, 'C:\Backups\SomeDatabaseBackup.bak'
至少在SQL Server 2014中,第二个参数(文件夹路径)可以是特定的文件名,这会导致仅删除该文件,例如:exec master.dbo.xp_DELETE_FILE 0,‘C:\Backups\SomeDatabaseBackup.bak’
As of SQL Server 2012, the xp_delete_file generated by Maintenance Plan does not have a trailing backslash in Folder Path.
从SQL Server 2012开始,维护计划生成的XP_DELETE_FILE在文件夹路径中没有尾随反斜杠。
我是一名优秀的程序员,十分优秀!