Insert Entity
The Insert Entity operation inserts a new entity into a table.
The Insert Entity request may be constructed as follows. Replace myaccount with the name of your storage account, and mytable with the name of your table:
| Method | Request URI | HTTP Version |
|---|---|---|
|
POST |
|
HTTP/1.1 |
When making a request against the local storage service, specify the local hostname and Table service port as 127.0.0.1:10002, followed by the local storage account name:
| Method | Request URI | HTTP Version |
|---|---|---|
|
POST |
|
HTTP/1.1 |
The Table service in the storage emulator differs from the Windows® Azure™ Table service in several ways. For more information, see Información general del emulador de almacenamiento de Windows Azure and Diferencias entre el emulador de almacenamiento y los servicios de almacenamiento de Windows Azure.
None.
The following table describes required and optional request headers.
| Request header | Description |
|---|---|
|
Authorization |
Required. Specifies the authentication scheme, account name, and signature. For more information, see Authentication Schemes. |
|
Date or x-ms-date |
Required. Specifies the Coordinated Universal Time (UTC) for the request. For more information, see Authentication Schemes. |
|
x-ms-version |
Optional. Specifies the version of the operation to use for this request. For more information, see Storage Services Versioning. |
|
Content-Type |
Required. The content type of the request body. Currently, this header should be set to application/atom+xml. |
|
Content-Length |
Required. The length of the request body. |
The Insert Entity operation sends the entity to be inserted as an ADO.NET entity set, which is an Atom feed. For more information, see Inserting and Updating Entities. For details about the specification for the Atom feed, see the Atom Serialization Rules (ADO.NET Data Services Framework) in the ADO.NET Data Service Specifications.
Here is a sample request body for the Insert Entity operation.
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<title />
<updated>2008-09-18T23:46:19.3857256Z<updated/>
<author>
<name />
</author>
<id />
<content type="application/xml">
<m:properties>
<d:Address>Mountain View</d:Address>
<d:Age m:type="Edm.Int32">23</d:Age>
<d:AmountDue m:type="Edm.Double">200.23</d:AmountDue>
<d:BinaryData m:type="Edm.Binary" m:null="true" />
<d:CustomerCode m:type="Edm.Guid">c9da6455-213d-42c9-9a79-3e9149a57833</d:CustomerCode>
<d:CustomerSince m:type="Edm.DateTime">2008-07-10T00:00:00</d:CustomerSince>
<d:IsActive m:type="Edm.Boolean">true</d:IsActive>
<d:NumOfOrders m:type="Edm.Int64">255</d:NumOfOrders>
<d:PartitionKey>mypartitionkey</d:PartitionKey>
<d:RowKey>myrowkey1</d:RowKey>
<d:Timestamp m:type="Edm.DateTime">0001-01-01T00:00:00</d:Timestamp>
</m:properties>
</content>
</entry>
The response includes an HTTP status code, a set of response headers, and a response body.
A successful operation returns status code 201 (Created).
For information about status codes, see Status and Error Codes and Table Service Error Codes.
The response includes the following headers. The response may also include additional standard HTTP headers. All standard headers conform to the HTTP/1.1 protocol specification.
| Response header | Description |
|---|---|
|
x-ms-request-id |
This header uniquely identifies the request that was made and can be used for troubleshooting the request. For more information, see Troubleshooting API Operations. |
|
x-ms-version |
Indicates the version of the Table service used to execute the request. This header is returned for requests made against version 2009-09-19 and later. |
|
Date |
A UTC date/time value generated by the service that indicates the time at which the response was initiated. |
The response body for the Insert Entity operation is also an ADO.NET entity set.
Here is a sample response body for the Insert Entity operation.
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xml:base="http://myaccount.table.core.windows.net/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:etag="W/"datetime'2008-09-18T23%3A46%3A19.4277424Z'"" xmlns="http://www.w3.org/2005/Atom">
<id>http://myaccount.table.core.windows.net/mytable(PartitionKey='mypartitionkey',RowKey='myrowkey1')</id>
<title type="text"></title>
<updated>2008-09-18T23:46:19.3857256Z</updated>
<author>
<name />
</author>
<link rel="edit" title="mytable" href="mytable(PartitionKey='mypartitionkey',RowKey='myrowkey1')" />
<category term="myaccount.Tables" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:PartitionKey>mypartitionkey</d:PartitionKey>
<d:RowKey>myrowkey1</d:RowKey>
<d:Timestamp m:type="Edm.DateTime">2008-09-18T23:46:19.4277424Z</d:Timestamp>
<d:Address>Mountain View</d:Address>
<d:Age m:type="Edm.Int32">23</d:Age>
<d:AmountDue m:type="Edm.Double">200.23</d:AmountDue>
<d:CustomerCode m:type="Edm.Guid">c9da6455-213d-42c9-9a79-3e9149a57833</d:CustomerCode>
<d:CustomerSince m:type="Edm.DateTime">2008-07-10T00:00:00</d:CustomerSince>
<d:IsActive m:type="Edm.Boolean">true</d:IsActive>
<d:NumOfOrders m:type="Edm.Int64">255</d:NumOfOrders>
</m:properties>
</content>
</entry>
Only the account owner may call this operation.
When inserting an entity into a table, you must specify values for the PartitionKey and RowKey system properties. Together, these properties form the primary key and must be unique within the table.
Both the PartitionKey and RowKey values must be string values; each key value may be up to 64 KB in size. If you are using an integer value for the key value, you should convert the integer to a fixed-width string, because they are canonically sorted. For example, you should convert the value 1 to 0000001 to ensure proper sorting.
To explicitly type a property, specify the appropriate ADO.NET Data Services type by setting the m:type attribute within the property definition in the Atom feed. For more information about typing properties, see Inserting and Updating Entities.
Any application that can authenticate and send an HTTP POST request can insert an entity. For more information about constructing a query by using HTTP POST, see POST Method (ADO.NET Data Services Framework).
Note that you can also use the .NET Client Library for ADO.NET Data Services to insert an entity into a table.
For information about performing batch insert operations, see Performing Entity Group Transactions.
Vea también