|
Azure Data Tables is a NoSQL data storage service that can be accessed from anywhere in the world via authenticated calls using HTTP or HTTPS. Tables scales as needed to support the amount of data inserted, and allows for the storing of data with non-complex accessing. The Azure Tables client can be used to access Azure Storage or Cosmos accounts.
Source code | Package (vcpkg) | API reference documentation | Product documentation | Samples
If you use the Azure CLI, replace <your-resource-group-name>
and <your-tables-name>
with your own, unique names:
The easiest way to acquire the C++ SDK is leveraging the vcpkg package manager and CMake. See the corresponding Azure SDK for C++ readme section. We'll use vcpkg in manifest mode. To start a vcpkg project in manifest mode use the following command at the root of your project:
To install the Azure <Service-Name> package via vcpkg: To add the Azure <Service-Name> package to your vcpkg enter the following command (We'll also add the Azure Identity library for authentication):
Then, add the following in your CMake file:
Remember to set CMAKE_TOOLCHAIN_FILE
to the path to vcpkg.cmake
either by adding the following to your CMakeLists.txt
file before your project statement:
Or by specifying it in your CMake commands with the -DCMAKE_TOOLCHAIN_FILE
argument.
There is more than one way to acquire and install this library. Check out our samples on different ways to set up your Azure C++ project.
Common uses of the table service include:
The following components make up the Azure Tables Service:
The Azure Tables client library for C++ allows you to interact with each of these components through the use of a dedicated client object.
The Azure Tables library allows you to interact with two types of resources:
endpoint
can be found on the page for your storage account in the [Azure Portal][azure_portal_account_url] under the "Access Keys" section or by running the following Azure CLI command:We'll be using the DefaultAzureCredential
to authenticate which will pick up the credentials we used when logging in with the Azure CLI earlier. DefaultAzureCredential
can pick up on a number of Credential types from your environment and is ideal when getting started and developing. Check out our section on DefaultAzureCredentials to learn more.
Two different clients are provided to interact with the various components of the Table Service:
TableServiceClient
** -TableClient
** -In order to Create/Delete a table we need to create a TableServiceClient
first.
In order to Delete a table we need to call the delete method on the previously created client.
To get the service properties we call the GetProperties method on the table service client.
To list the tables in the account we call the ListTables method on the table service client.
To get the statistics of the account we call the GetStatistics method on the table service client.
The TableClient is used to interact with table entities and perform operations on them.
We create a table on which we run the transaction and get a table client.
N.B. Here we are obtaining the table client from the table service client using the credentials that were passed to the table service client.
In order to Create/Update/Merge/Delete entities we need to create a TablesClient first.
Entities are similar to rows. An entity has a set of properties, including a **PartitionKey
** and **RowKey
** which form the primary key of the entity. A property is a name value pair, similar to a column. Every entity in a table does not need to have the same properties.
Then we initialize and populate an entity.
To create the entity on the server we call the CreateEntity method on the table client.
To update the entity, assume we made some changes to the entity, we call the UpdateEntity method on the table client.
To merge the entity, assume we made some changes to the entity, we call the MergeEntity method on the table client.
To delete the entity, we call the DeleteEntity method on the table client.
We initialize and populate the entities.
We create a transaction batch and add the operations to the transaction.
We then submit the transaction and check the response.
The output of this sample is:
The difference from the previous example is that we are trying to add two entities with the same PartitionKey and RowKey.
The rest of the steps are the same as in the previous example.
The output of the sample contains the error message:
See the C++ Contributing Guide for details on building, testing, and contributing to these libraries.
See the Storage Testing Guide for how to set up storage resources running unit tests.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.microsoft.com.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.