C++ ile Tablo için Azure Tablo depolama ve Azure Cosmos DB kullanma

ŞUNLAR IÇIN GEÇERLIDIR: Tablo

İpucu

Bu makaledeki içerik, Azure Tablo depolama ve Tablo için Azure Cosmos DB için geçerlidir. Tablo için API, aktarım hızı için iyileştirilmiş tablolar, genel dağıtım ve otomatik ikincil dizinler sunan, tablo depolamaya yönelik premium bir tekliftir.

Bu kılavuz, Azure Tablo depolama hizmetini veya Tablo için Azure Cosmos DB'yi kullanarak yaygın senaryoları gösterir. Örnekler C++ dilinde yazılmıştır ve C++ için Azure Depolama İstemci Kitaplığı’nı kullanır. Bu makale, aşağıdaki senaryoları destekler:

  • Tablo oluşturma ve silme
  • Tablo varlıklarıyla çalışma

Not

Bu kılavuz C++ için Azure Depolama İstemci Kitaplığı sürüm 1.0.0 ve üzerini hedefler. Önerilen sürüm, NuGet veya GitHub kullanılarak kullanılabilen Depolama İstemci Kitaplığı 2.2.0'dır.

Hesap oluşturma

Azure hizmet hesabı oluşturma

Azure Tablo depolama alanını veya Azure Cosmos DB'yi kullanarak tablolarla çalışabilirsiniz. Bu iki hizmetteki tablo teklifleri arasındaki farklar hakkında daha fazla bilgi edinmek için Tabloya genel bakış API'sine bakın. Kullanacağınız hizmet için bir hesap oluşturmanız gerekir. Aşağıdaki bölümlerde hem Azure Tablo depolamanın hem de Azure Cosmos DB hesabının nasıl oluşturulacağı gösterilmektedir, ancak bunlardan yalnızca birini kullanabilirsiniz.

Azure Depolama hesabı oluşturma

Azure depolama hesabı oluşturmanın en kolay yolu Azure portalını kullanmaktır. Daha fazla bilgi almak için bkz. Depolama hesabı oluşturma.

Azure PowerShell veya Azure CLI kullanarak da bir Azure depolama hesabı oluşturabilirsiniz.

Şu anda depolama hesabı oluşturmamak isterseniz, kodunuzu yerel bir ortamda çalıştırmak ve test etmek için Azure Depolama Öykünücüsü'ni de kullanabilirsiniz. Daha fazla bilgi için bkz. Geliştirme ve test için Azure Depolama Öykünücüsü'ni kullanma.

Tablo hesabı için Azure Cosmos DB oluşturma

Tablo hesabı için Azure Cosmos DB oluşturma yönergeleri için bkz . Veritabanı hesabı oluşturma.

C++ uygulaması oluşturma

Bu kılavuzda, bir C++ uygulamasından depolama özelliklerini kullanacaksınız. Bunu yapmak için C++ için Azure Depolama İstemci Kitaplığı'nı yükleyin.

C++ için Azure Depolama İstemci Kitaplığı'nı yüklemek için aşağıdaki yöntemleri kullanın:

.\vcpkg.exe install azure-storage-cpp

Kaynak kodu derleme ve Nuget'e dışarı aktarma hakkında bir kılavuzu README dosyasında bulabilirsiniz.

Tablo istemci kitaplığına erişimi yapılandırma

Azure depolama API'lerini kullanarak tablolara erişmek için C++ dosyasının en üstüne aşağıdaki include deyimleri ekleyin:

#include <was/storage_account.h>
#include <was/table.h>

Azure Depolama istemcisi veya Azure Cosmos DB istemcisi, veri yönetimi hizmetlerine erişmek için uç noktaları ve kimlik bilgilerini depolamak için bir bağlantı dizesi kullanır. bir istemci uygulaması çalıştırdığınızda depolama bağlantı dizesi veya Azure Cosmos DB bağlantı dizesi uygun biçimde sağlamanız gerekir.

Azure Depolama bağlantı dizesini ayarlama

Bu örnekte, Azure Depolama bağlantı dizesi tutmak için statik alan bildirme adımları gösterilmektedir:

// Define the Storage connection string with your values.
const utility::string_t storage_connection_string(U("DefaultEndpointsProtocol=https;AccountName=<your_storage_account>;AccountKey=<your_storage_account_key>"));

için <your_storage_account>Depolama hesabınızın adını kullanın. your_storage_account_key <>için Azure portalında listelenen Depolama hesabının erişim anahtarını kullanın. Depolama hesapları ve erişim anahtarları hakkında bilgi için bkz. Depolama hesabı oluşturma.

Azure Cosmos DB bağlantı dizesini ayarlama

Bu örnekte, Azure Cosmos DB bağlantı dizesi tutmak için statik alan bildirme adımları gösterilmektedir:

// Define the Azure Cosmos DB connection string with your values.
const utility::string_t storage_connection_string(U("DefaultEndpointsProtocol=https;AccountName=<your_cosmos_db_account>;AccountKey=<your_cosmos_db_account_key>;TableEndpoint=<your_cosmos_db_endpoint>"));

için <your_cosmos_db_account>Azure Cosmos DB hesabınızın adını kullanın. için <your_cosmos_db_account_key>birincil anahtarınızı girin. için <your_cosmos_db_endpoint>Azure portalında listelenen uç noktayı girin.

Uygulamanızı yerel Windows tabanlı bilgisayarınızda test etmek için, Azure SDK ile yüklenen Azure Depolama Öykünücüsü'ni kullanabilirsiniz. Depolama Öykünücüsü, yerel geliştirme makinenizde bulunan Azure Blob, Kuyruk ve Tablo hizmetlerinin simülasyonunu sağlayan bir yardımcı programdır. Aşağıdaki örnekte, yerel depolama öykünücünüze bağlantı dizesi tutmak için statik bir alanın nasıl bildir olduğu gösterilmektedir:

// Define the connection string with Azure Storage Emulator.
const utility::string_t storage_connection_string(U("UseDevelopmentStorage=true;"));  

Azure Depolama Öykünücüsü'nü başlatmak için Windows masaüstünüzden Başlangıç düğmesini veya Windows tuşunu seçin. Microsoft Azure Depolama Öykünücüsü'ne girin ve çalıştırın. Daha fazla bilgi için bkz. Geliştirme ve test için Azure Depolama Öykünücüsü'ni kullanma.

Bağlantı dizenizi alma

depolama hesabı bilgilerinizi göstermek için sınıfını cloud_storage_account kullanabilirsiniz. Depolama hesabı bilgilerinizi depolama bağlantı dizesi almak için yöntemini kullanınparse.

// Retrieve the storage account from the connection string.
azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);

Ardından, bir cloud_table_client sınıfa başvuru alın. Bu sınıf, Tablo depolama hizmetinde depolanan tablolar ve varlıklar için başvuru nesneleri almanıza olanak tanır. Aşağıdaki kod, daha önce aldığınız depolama hesabı nesnesini kullanarak bir cloud_table_client nesne oluşturur:

// Create the table client.
azure::storage::cloud_table_client table_client = storage_account.create_cloud_table_client();

Tablo oluşturma ve tabloya varlık ekleme

Tablo oluştur

Nesne cloud_table_client , tablolar ve varlıklar için başvuru nesneleri almanıza olanak tanır. Aşağıdaki kod bir cloud_table_client nesne oluşturur ve bunu kullanarak yeni bir tablo oluşturur.

// Retrieve the storage account from the connection string.
azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);  

// Create the table client.
azure::storage::cloud_table_client table_client = storage_account.create_cloud_table_client();

// Retrieve a reference to a table.
azure::storage::cloud_table table = table_client.get_table_reference(U("people"));

// Create the table if it doesn't exist.
table.create_if_not_exists();  

Tabloya bir varlık ekleme

Tabloya varlık eklemek için yeni table_entity bir nesne oluşturun ve öğesine geçirin table_operation::insert_entity. Aşağıdaki kod, satır anahtarı olarak müşterinin adını, bölüm anahtarı olarak soyadını kullanır. Birlikte, bir varlığın bölüm ve sıra anahtarı varlığı tabloda benzersiz şekilde tanımlar. Aynı bölüm anahtarına sahip varlıklar, farklı bölüm anahtarları olan varlıklara göre daha hızlı sorgulanabilir. Farklı bölüm anahtarlarının kullanılması, paralel işlem ölçeklenebilirliğinin daha fazla kullanılmasını sağlar. Daha fazla bilgi için bkz. Microsoft Azure depolama performansı ve ölçeklenebilirliği yapılacaklar listesi.

Aşağıdaki kod, depo için bazı müşteri verileriyle yeni bir örneği table_entity oluşturur. Kod daha sonra bir tabloya varlık table_operation eklemek üzere bir nesne oluşturmak için öğesini çağırır table_operation::insert_entity ve yeni tablo varlığını onunla ilişkilendirir. Son olarak, kod nesnesinde executecloud_table yöntemini çağırır. Yeni table_operation , tabloya yeni müşteri varlığını people eklemek için Tablo hizmetine bir istek gönderir.

// Retrieve the storage account from the connection string.
azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);

// Create the table client.
azure::storage::cloud_table_client table_client = storage_account.create_cloud_table_client();

// Retrieve a reference to a table.
azure::storage::cloud_table table = table_client.get_table_reference(U("people"));

// Create the table if it doesn't exist.
table.create_if_not_exists();

// Create a new customer entity.
azure::storage::table_entity customer1(U("Harp"), U("Walter"));

azure::storage::table_entity::properties_type& properties = customer1.properties();
properties.reserve(2);
properties[U("Email")] = azure::storage::entity_property(U("Walter@contoso.com"));

properties[U("Phone")] = azure::storage::entity_property(U("425-555-0101"));

// Create the table operation that inserts the customer entity.
azure::storage::table_operation insert_operation = azure::storage::table_operation::insert_entity(customer1);

// Execute the insert operation.
azure::storage::table_result insert_result = table.execute(insert_operation);

Toplu işlem varlık yerleştirme

Tablo hizmetine tek bir yazma işlemiyle çok sayıda varlık ekleyebilirsiniz. Aşağıdaki kod bir table_batch_operation nesne oluşturur ve sonra bu nesneye üç ekleme işlemi ekler. Her ekleme işlemi, yeni bir varlık nesnesi oluşturularak, değerleri ayarlanarak ve sonra varlığı yeni bir ekleme işlemiyle ilişkilendirmek için nesnede table_batch_operation yöntemini çağırarak insert eklenir. Ardından kod, işlemi çalıştırmak için çağırır cloud_table.execute .

// Retrieve the storage account from the connection string.
azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);

// Create the table client.
azure::storage::cloud_table_client table_client = storage_account.create_cloud_table_client();

// Create a cloud table object for the table.
azure::storage::cloud_table table = table_client.get_table_reference(U("people"));

// Define a batch operation.
azure::storage::table_batch_operation batch_operation;

// Create a customer entity and add it to the table.
azure::storage::table_entity customer1(U("Smith"), U("Jeff"));

azure::storage::table_entity::properties_type& properties1 = customer1.properties();
properties1.reserve(2);
properties1[U("Email")] = azure::storage::entity_property(U("Jeff@contoso.com"));
properties1[U("Phone")] = azure::storage::entity_property(U("425-555-0104"));

// Create another customer entity and add it to the table.
azure::storage::table_entity customer2(U("Smith"), U("Ben"));

azure::storage::table_entity::properties_type& properties2 = customer2.properties();
properties2.reserve(2);
properties2[U("Email")] = azure::storage::entity_property(U("Ben@contoso.com"));
properties2[U("Phone")] = azure::storage::entity_property(U("425-555-0102"));

// Create a third customer entity to add to the table.
azure::storage::table_entity customer3(U("Smith"), U("Denise"));

azure::storage::table_entity::properties_type& properties3 = customer3.properties();
properties3.reserve(2);
properties3[U("Email")] = azure::storage::entity_property(U("Denise@contoso.com"));
properties3[U("Phone")] = azure::storage::entity_property(U("425-555-0103"));

// Add customer entities to the batch insert operation.
batch_operation.insert_or_replace_entity(customer1);
batch_operation.insert_or_replace_entity(customer2);
batch_operation.insert_or_replace_entity(customer3);

// Execute the batch operation.
std::vector<azure::storage::table_result> results = table.execute_batch(batch_operation);

Toplu işlemlerde dikkat edilecek bazı noktalar:

  • Tek bir toplu işlemde herhangi bir birleşimde en fazla 100 insert, mergedelete, , replace, insert-or-merge, ve insert-or-replace işlemi yapabilirsiniz.
  • Toplu işlemde tek işlem buysa, toplu işlem bir alma işlemine sahip olabilir.
  • Tek bir toplu işlemdeki tüm varlıkların bölüm anahtarları aynı olmalıdır.
  • Toplu işlem 4 MB veri yükü ile sınırlıdır.

Varlıkları sorgulama ve değiştirme

Tüm varlıkları bir bölüme alma

Bir bölümdeki tüm varlıkların tablosunu sorgulamak için bir table_query nesne kullanın. Aşağıdaki kod örneği, bölüm anahtarı olan Smith varlıklar için bir filtre belirtir. Bu örnek sorgu sonuçlarındaki her varlığın alanlarını konsola yazdırır.

Not

Bu yöntemler şu anda Azure Cosmos DB’de C++ için desteklenmemektedir.

// Retrieve the storage account from the connection string.
azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);

// Create the table client.
azure::storage::cloud_table_client table_client = storage_account.create_cloud_table_client();

// Create a cloud table object for the table.
azure::storage::cloud_table table = table_client.get_table_reference(U("people"));

// Construct the query operation for all customer entities where PartitionKey="Smith".
azure::storage::table_query query;

query.set_filter_string(azure::storage::table_query::generate_filter_condition(U("PartitionKey"), azure::storage::query_comparison_operator::equal, U("Smith")));

// Execute the query.
azure::storage::table_query_iterator it = table.execute_query(query);

// Print the fields for each customer.
azure::storage::table_query_iterator end_of_results;
for (; it != end_of_results; ++it)
{
    const azure::storage::table_entity::properties_type& properties = it->properties();

    std::wcout << U("PartitionKey: ") << it->partition_key() << U(", RowKey: ") << it->row_key()
        << U(", Property1: ") << properties.at(U("Email")).string_value()
        << U(", Property2: ") << properties.at(U("Phone")).string_value() << std::endl;
}  

Bu örnekteki sorgu, filtre ölçütlerine uyan tüm varlıkları döndürür. Büyük tablolarınız varsa ve tablo varlıklarını sık indirmeniz gerekiyorsa, verilerinizi bunun yerine Azure depolama bloblarında depolamanız önerilir.

Bir bölüme bir grup varlık alma

Bir bölümdeki tüm varlıkları sorgulamak istemiyorsanız bir aralık belirtebilirsiniz. Bölüm anahtarı filtresini satır anahtarı filtresiyle birleştirin. Aşağıdaki kod örneği, satır anahtarının (ad) alfabeden E önceki bir harfle başladığı ve ardından sorgu sonuçlarını yazdırdığı bölümdeki Smith tüm varlıkları almak için iki filtre kullanır.

Not

Bu yöntemler şu anda Azure Cosmos DB’de C++ için desteklenmemektedir.

// Retrieve the storage account from the connection string.
azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);

// Create the table client.
azure::storage::cloud_table_client table_client = storage_account.create_cloud_table_client();

// Create a cloud table object for the table.
azure::storage::cloud_table table = table_client.get_table_reference(U("people"));

// Create the table query.
azure::storage::table_query query;

query.set_filter_string(azure::storage::table_query::combine_filter_conditions(
    azure::storage::table_query::generate_filter_condition(U("PartitionKey"),
    azure::storage::query_comparison_operator::equal, U("Smith")),
    azure::storage::query_logical_operator::op_and,
    azure::storage::table_query::generate_filter_condition(U("RowKey"), azure::storage::query_comparison_operator::less_than, U("E"))));

// Execute the query.
azure::storage::table_query_iterator it = table.execute_query(query);

// Loop through the results, displaying information about the entity.
azure::storage::table_query_iterator end_of_results;
for (; it != end_of_results; ++it)
{
    const azure::storage::table_entity::properties_type& properties = it->properties();

    std::wcout << U("PartitionKey: ") << it->partition_key() << U(", RowKey: ") << it->row_key()
        << U(", Property1: ") << properties.at(U("Email")).string_value()
        << U(", Property2: ") << properties.at(U("Phone")).string_value() << std::endl;
}  

Tek bir varlık alma

Tek, belirli bir varlığı almak üzere bir sorgu yazabilirsiniz. Aşağıdaki kod müşteriyi Jeff Smithbelirtmek için kullanırtable_operation::retrieve_entity. Bu yöntem koleksiyon yerine yalnızca bir varlık döndürür ve döndürülen değer içindedir table_result. Bir sorguda hem bölüm hem de satır anahtarını belirtmek Tablo hizmetinden tek bir varlık almanın en hızlı yoludur.

azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);

// Create the table client.
azure::storage::cloud_table_client table_client = storage_account.create_cloud_table_client();

// Create a cloud table object for the table.
azure::storage::cloud_table table = table_client.get_table_reference(U("people"));

// Retrieve the entity with partition key of "Smith" and row key of "Jeff".
azure::storage::table_operation retrieve_operation = azure::storage::table_operation::retrieve_entity(U("Smith"), U("Jeff"));
azure::storage::table_result retrieve_result = table.execute(retrieve_operation);

// Output the entity.
azure::storage::table_entity entity = retrieve_result.entity();
const azure::storage::table_entity::properties_type& properties = entity.properties();

std::wcout << U("PartitionKey: ") << entity.partition_key() << U(", RowKey: ") << entity.row_key()
    << U(", Property1: ") << properties.at(U("Email")).string_value()
    << U(", Property2: ") << properties.at(U("Phone")).string_value() << std::endl;

Bir varlığı değiştirme

Bir varlığı değiştirmek için Tablo hizmetinden alın, varlık nesnesini değiştirin ve değişiklikleri Tablo hizmetine geri kaydedin. Aşağıdaki kod mevcut bir müşterinin telefon numarasını ve e-posta adresini değiştirir. bu kod, çağrısı table_operation::insert_entityyapmak yerine kullanır table_operation::replace_entity. Bu yaklaşım, sunucudaki varlık alındıktan sonra değişmediği sürece varlığın sunucuda tamamen değiştirilmesine neden olur. Değiştirilmişse, işlem başarısız olur. Bu hata, uygulamanızın başka bir bileşen tarafından alma ve güncelleştirme arasında yapılan değişikliğin üzerine yazmasını engeller. Bu hatanın doğru şekilde işlenmesi, varlığı yeniden almak, değişikliklerinizi (hala geçerliyse) yapmak ve sonra başka bir table_operation::replace_entity işlem yapmaktır.

// Retrieve the storage account from the connection string.
azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);

// Create the table client.
azure::storage::cloud_table_client table_client = storage_account.create_cloud_table_client();

// Create a cloud table object for the table.
azure::storage::cloud_table table = table_client.get_table_reference(U("people"));

// Replace an entity.
azure::storage::table_entity entity_to_replace(U("Smith"), U("Jeff"));
azure::storage::table_entity::properties_type& properties_to_replace = entity_to_replace.properties();
properties_to_replace.reserve(2);

// Specify a new phone number.
properties_to_replace[U("Phone")] = azure::storage::entity_property(U("425-555-0106"));

// Specify a new email address.
properties_to_replace[U("Email")] = azure::storage::entity_property(U("JeffS@contoso.com"));

// Create an operation to replace the entity.
azure::storage::table_operation replace_operation = azure::storage::table_operation::replace_entity(entity_to_replace);

// Submit the operation to the Table service.
azure::storage::table_result replace_result = table.execute(replace_operation);

Varlık ekleme veya değiştirme

table_operation::replace_entity varlık sunucudan alındığından bu yana değiştirilmişse işlemler başarısız olur. Ayrıca, başarılı olmak için table_operation::replace_entity önce sunucudan varlığı almanız gerekir. Bazen varlığın sunucuda var olup olmadığını bilmezsiniz. Güncelleştirmenizin tümünün üzerine yazılması gerektiğinden, içinde depolanan geçerli değerler ilgisizdir. Bu sonucu elde etmek için bir table_operation::insert_or_replace_entity işlem kullanın. Bu işlem, mevcut değilse varlığı ekler. İşlem, varsa varlığın yerini alır. Aşağıdaki kod örneğinde, için Jeff Smith müşteri varlığı alınmaya devam eder, ancak daha sonra kullanılarak table_operation::insert_or_replace_entitysunucuya geri kaydedilir. Varlığa alma ve güncelleştirme işlemleri arasında yapılan tüm güncelleştirmelerin üzerine yazılacaktır.

// Retrieve the storage account from the connection string.
azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);

// Create the table client.
azure::storage::cloud_table_client table_client = storage_account.create_cloud_table_client();

// Create a cloud table object for the table.
azure::storage::cloud_table table = table_client.get_table_reference(U("people"));

// Insert or replace an entity.
azure::storage::table_entity entity_to_insert_or_replace(U("Smith"), U("Jeff"));
azure::storage::table_entity::properties_type& properties_to_insert_or_replace = entity_to_insert_or_replace.properties();

properties_to_insert_or_replace.reserve(2);

// Specify a phone number.
properties_to_insert_or_replace[U("Phone")] = azure::storage::entity_property(U("425-555-0107"));

// Specify an email address.
properties_to_insert_or_replace[U("Email")] = azure::storage::entity_property(U("Jeffsm@contoso.com"));

// Create an operation to insert or replace the entity.
azure::storage::table_operation insert_or_replace_operation = azure::storage::table_operation::insert_or_replace_entity(entity_to_insert_or_replace);

// Submit the operation to the Table service.
azure::storage::table_result insert_or_replace_result = table.execute(insert_or_replace_operation);

Giriş özellikleri alt kümesi sorgulama

Tabloya gönderilen bir sorgu, bir varlıktan yalnızca birkaç özellik alabilir. Aşağıdaki koddaki sorgu, yalnızca tablodaki varlıkların e-posta adreslerini döndürmek için yöntemini kullanır table_query::set_select_columns .

// Retrieve the storage account from the connection string.
azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);

// Create the table client.
azure::storage::cloud_table_client table_client = storage_account.create_cloud_table_client();

// Create a cloud table object for the table.
azure::storage::cloud_table table = table_client.get_table_reference(U("people"));

// Define the query, and select only the Email property.
azure::storage::table_query query;
std::vector<utility::string_t> columns;

columns.push_back(U("Email"));
query.set_select_columns(columns);

// Execute the query.
azure::storage::table_query_iterator it = table.execute_query(query);

// Display the results.
azure::storage::table_query_iterator end_of_results;
for (; it != end_of_results; ++it)
{
    std::wcout << U("PartitionKey: ") << it->partition_key() << U(", RowKey: ") << it->row_key();

    const azure::storage::table_entity::properties_type& properties = it->properties();
    for (auto prop_it = properties.begin(); prop_it != properties.end(); ++prop_it)
    {
        std::wcout << ", " << prop_it->first << ": " << prop_it->second.str();
    }

    std::wcout << std::endl;
}

Not

Bir varlıktaki birkaç özelliğin sorgulanması, tüm özelliklerin alınmasından daha verimli bir işlemdir.

İçeriği sil

Varlığı silme

Bir varlığı aldıktan sonra silebilirsiniz. Bir varlığı aldıktan sonra silinecek varlıkla birlikte çağrısında table_operation::delete_entity bulunabilirsiniz. Ardından yöntemini çağırın cloud_table.execute . Aşağıdaki kod, bölüm anahtarı ve satır Jeffanahtarı Smith olan bir varlığı alır ve siler.

// Retrieve the storage account from the connection string.
azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);

// Create the table client.
azure::storage::cloud_table_client table_client = storage_account.create_cloud_table_client();

// Create a cloud table object for the table.
azure::storage::cloud_table table = table_client.get_table_reference(U("people"));

// Create an operation to retrieve the entity with partition key of "Smith" and row key of "Jeff".
azure::storage::table_operation retrieve_operation = azure::storage::table_operation::retrieve_entity(U("Smith"), U("Jeff"));
azure::storage::table_result retrieve_result = table.execute(retrieve_operation);

// Create an operation to delete the entity.
azure::storage::table_operation delete_operation = azure::storage::table_operation::delete_entity(retrieve_result.entity());

// Submit the delete operation to the Table service.
azure::storage::table_result delete_result = table.execute(delete_operation);  

Tablo silme

Son olarak aşağıdaki kod örneği bir depolama hesabından bir tablo siler. Silinmiş olan bir tablo, silme işleminden sonra bir süre yeniden oluşturulamıyor.

// Retrieve the storage account from the connection string.
azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);

// Create the table client.
azure::storage::cloud_table_client table_client = storage_account.create_cloud_table_client();

// Create a cloud table object for the table.
azure::storage::cloud_table table = table_client.get_table_reference(U("people"));

// Delete the table if it exists
if (table.delete_table_if_exists())
{
    std::cout << "Table deleted!";
}
else
{
    std::cout << "Table didn't exist";
}

Sorun giderme

Visual Studio Community Edition için projeniz storage_account.h ve table.h dahil dosyaları nedeniyle derleme hataları alıyorsa /permissive- derleyici anahtarını kaldırın:

  1. Çözüm Gezgini’nde projenize sağ tıklayın ve Özellikler’i seçin.
  2. Özellik Sayfaları iletişim kutusunda Yapılandırma Özellikleri’ni, C/C++’yi genişletin ve Dil’i seçin.
  3. Uyumluluk modu’nu Hayır olarak ayarlayın.

Sonraki adımlar

Microsoft Azure Depolama Gezgini, Microsoft’un Windows, macOS ve Linux üzerinde Azure Depolama verileriyle görsel olarak çalışmanızı sağlayan ücretsiz ve tek başına uygulamasıdır.

Azure cosmos DB'de Azure Depolama ve Tablo API'si hakkında daha fazla bilgi edinmek için şu bağlantıları izleyin: