---
title: "在SQL Server中使用SQL命令删除文件"
author: "bluestorm"
date: "2009-12-08T14:58:25Z"
tags: []
categories: ["数据库"]
slug: "sql-server-sql"
draft: false
lastmod: "2009-12-08T14:58:42Z"
id: 544090
url: "https://bluestorm.iteye.com/blog/544090"
---

```
exec master.dbo.xp_cmdshell 'del D:\test.txt' 
```

 

在SQL Server中，这个语句可以用来删除D盘下的test.txt文件。

如果'xp\_cmdshell'没有启用，可以使用下列语句启用'xp\_cmdshell':

```
exec sp_configure 'show advanced options', 1; 
reconfigure; 
exec sp_configure 'xp_cmdshell', 1; 
reconfigure;
```

   
其中，'1' 表示启用，'0' 表示停用。