

# DeleteItem
<a name="API_DeleteItem_v20111205"></a>

**重要**  
***本节介绍已经弃用的 API 版本 2011-12-05，不应用于新应用程序。***  
 **有关当前低级别 API 的文档，请参阅 [Amazon DynamoDB API 参考](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/)。**

## 描述
<a name="API_DeleteItem_Description"></a>

按主键删除表中的单个项目。可以执行条件删除操作，如果项目存在或者具有预期属性值，则删除该项目。

**注意**  
如果指定没有属性或值的 `DeleteItem`，则将删除该项目的所有属性。  
除非指定条件，否则 `DeleteItem` 是一个幂等操作；在同一个项目或属性上多次运行*不会*导致出现错误响应。  
条件删除用于只有满足特定条件，才删除项目和属性的情况。如果满足这些条件，DynamoDB 将执行删除。否则，不会删除项目。  
您可以在每个操作中对一个属性执行预期条件检查。

## 请求
<a name="API_DeleteItem_RequestParameters"></a>

### 语法
<a name="API_DeleteItem_RequestParameters.syntax"></a>

```
// This header is abbreviated. 
// For a sample of a complete header, see DynamoDB 低级 API.
POST / HTTP/1.1 
x-amz-target: DynamoDB_20111205.DeleteItem 
content-type: application/x-amz-json-1.0 

{"TableName":"Table1",
    "Key":
        {"HashKeyElement":{"S":"AttributeValue1"},"RangeKeyElement":{"N":"AttributeValue2"}},
    "Expected":{"AttributeName3":{"Value":{"S":"AttributeValue3"}}},
    "ReturnValues":"ALL_OLD"}
}
```


****  

|  名称  |  描述  |  必填 | 
| --- | --- | --- | 
|  TableName  |  包含要删除项目的表的名称。 类型：字符串  |  是  | 
|  Key  | 定义项目的主键。有关主键的更多信息，请参阅 [主键](HowItWorks.CoreComponents.md#HowItWorks.CoreComponents.PrimaryKey)。类型：`HashKeyElement` 到其值以及 `RangeKeyElement` 到其值的映射。 | 是 | 
| Expected  | 指定条件删除的属性。`Expected` 参数用于提供属性名称，以及 DynamoDB 是否应在删除前检查属性是否具有特定值。类型：属性名称映射。 | 否 | 
| Expected:AttributeName  | 条件放入的属性的名称。类型：字符串 | 否 | 
| Expected:AttributeName: ExpectedAttributeValue | 使用此参数指定属性名称-值对是否已经存在值。如果项目不存在“Color”属性，则下面的 JSON 表示将删除该项目：<pre>"Expected" :<br />	{"Color":{"Exists":false}}</pre>下面的 JSON 表示在删除项目前，检查“Color”名称的属性是否已有“Yellow”值：<pre>"Expected" : <br />	{"Color":{"Exists":true},{"Value":{"S":"Yellow"}}}</pre>默认情况下，如果使用 `Expected` 参数并提供 `Value`，则 DynamoDB 假定属性存在，并且需要替换当前值。这样不必指定 `{"Exists":true}`，因为是暗含的。可以将请求缩短为：<pre>"Expected" : <br />	{"Color":{"Value":{"S":"Yellow"}}}</pre> 如果指定的 `{"Exists":true}` 没有要检查的属性值，DynamoDB 将返回错误。  | 否 | 
| ReturnValues  | 如果要在删除属性名称-值对之前获取属性名称-值对，请使用此参数。可能的参数值包括 `NONE`（默认值）或 `ALL_OLD`。如果指定 `ALL_OLD`，则返回旧项目的内容。如果不提供此参数或者为 `NONE`，则不返回任何内容。类型：字符串 | 否 | 

## 响应
<a name="API_DeleteItem_CommonResponseElements"></a>

### 语法
<a name="API_DeleteItem_CommonResponseElements.syntax"></a>

```
HTTP/1.1 200 OK
x-amzn-RequestId: CSOC7TJPLR0OOKIRLGOHVAICUFVV4KQNSO5AEMVJF66Q9ASUAAJG
content-type: application/x-amz-json-1.0
content-length: 353
Date: Tue, 12 Jul 2011 21:31:03 GMT

{"Attributes":
    {"AttributeName3":{"SS":["AttributeValue3","AttributeValue4","AttributeValue5"]},
    "AttributeName2":{"S":"AttributeValue2"},
    "AttributeName1":{"N":"AttributeValue1"}
    },
"ConsumedCapacityUnits":1
}
```


****  

|  名称  |  描述  | 
| --- | --- | 
|  Attributes  | 如果提供 `ReturnValues` 参数作为请求的 `ALL_OLD`，DynamoDB 将返回属性名称-值对数组（即已删除的项目）。否则，响应包含一个空集合。类型：属性名称-值对的数组。 | 
| ConsumedCapacityUnits | 操作消耗的写入容量单位数。此值显示应用于预置吞吐量的数字。对不存在项目的删除请求消耗 1 个写入容量单位。有关更多信息，请参阅[DynamoDB 预置容量模式](provisioned-capacity-mode.md)。 类型：数字 | 

## 特殊错误
<a name="API_DeleteItem_SpecialErrors"></a>


****  

|  错误  |  描述  | 
| --- | --- | 
|  ConditionalCheckFailedException  | 条件检查失败。找不到预期的属性值。 | 

## 示例
<a name="API_DeleteItem_Examples"></a>

### 示例请求
<a name="API_DeleteItem_Examples_Request"></a>

```
// This header is abbreviated. 
// For a sample of a complete header, see DynamoDB 低级 API.
POST / HTTP/1.1 
x-amz-target: DynamoDB_20111205.DeleteItem 
content-type: application/x-amz-json-1.0

{"TableName":"comp-table",
    "Key":
        {"HashKeyElement":{"S":"Mingus"},"RangeKeyElement":{"N":"200"}},
    "Expected":
        {"status":{"Value":{"S":"shopping"}}},
    "ReturnValues":"ALL_OLD"
}
```

### 示例响应
<a name="API_DeleteItem_Examples_Response"></a>

```
HTTP/1.1 200 OK
x-amzn-RequestId: U9809LI6BBFJA5N2R0TB0P017JVV4KQNSO5AEMVJF66Q9ASUAAJG
content-type: application/x-amz-json-1.0
content-length: 353
Date: Tue, 12 Jul 2011 22:31:23 GMT

{"Attributes":
    {"friends":{"SS":["Dooley","Ben","Daisy"]},
    "status":{"S":"shopping"},
    "time":{"N":"200"},
    "user":{"S":"Mingus"}
    },
"ConsumedCapacityUnits":1
}
```

## 相关操作
<a name="API_DeleteItem_Related_Actions"></a>
+  [PutItem](API_PutItem_v20111205.md) 