Cara menggunakan penyimpanan Azure Table dan Azure Cosmos DB for Table dengan C++

BERLAKU UNTUK: Meja

Tip

Konten dalam artikel ini berlaku untuk penyimpanan Azure Table dan Azure Cosmos DB for Table. API untuk Tabel adalah penawaran premium untuk penyimpanan tabel yang menawarkan tabel yang dioptimalkan throughput, distribusi global, dan indeks sekunder otomatis.

Panduan ini menunjukkan skenario umum dengan menggunakan layanan penyimpanan Azure Table atau Azure Cosmos DB for Table. Sampel ditulis dalam C++ dan menggunakan Pustaka Klien Azure Storage untuk C++. Artikel ini membahas skenario berikut:

  • Membuat dan menghapus tabel
  • Menggunakan entitas tabel

Catatan

Panduan ini menargetkan pustaka klien Azure Storage untuk C++ v1.1.0.0 ke atas. Versi yang direkomendasikan adalah pustaka klien Storage Client Library 2.2.0, yang tersedia dengan menggunakan NuGet atau GitHub.

Membuat akun

Membuat akun layanan Azure

Anda dapat bekerja dengan tabel menggunakan penyimpanan Azure Table atau Azure Cosmos DB. Untuk mempelajari selengkapnya tentang perbedaan antara penawaran tabel di kedua layanan ini, lihat gambaran umum API untuk Tabel. Anda harus membuat akun untuk layanan yang akan Anda gunakan. Bagian berikut menunjukkan cara membuat penyimpanan Azure Table dan akun Azure Cosmos DB, tetapi Anda bisa menggunakan salah satunya.

Membuat akun Azure Storage

Cara termudah untuk membuat akun penyimpanan Azure adalah dengan menggunakan portal Azure. Untuk mempelajari selengkapnya, lihat Buat akun penyimpanan.

Anda juga bisa membuat akun penyimpanan Azure dengan menggunakan Azure PowerShell atau Azure CLI.

Jika Anda lebih suka tidak membuat akun penyimpanan saat ini, Anda juga dapat menggunakan Azure Storage emulator untuk menjalankan dan menguji kode Anda di lingkungan lokal. Untuk informasi selengkapnya, lihat Menggunakan Azure Storage Emulator untuk pengembangan dan pengujian.

Membuat akun Azure Cosmos DB for Table

Untuk instruksi tentang membuat akun Azure Cosmos DB for Table, lihat Membuat akun database.

Membuat aplikasi C++

Dalam panduan ini, Anda menggunakan fitur penyimpanan dari aplikasi C++. Untuk melakukannya, instal Pustaka Klien Azure Storage untuk C++.

Untuk menginstal Pustaka Klien Azure Storage untuk C++, gunakan metode berikut:

.\vcpkg.exe install azure-storage-cpp

Anda dapat menemukan panduan cara membuat kode sumber dan mengekspor ke Nuget dalam file README.

Mengonfigurasi akses ke pustaka klien Tabel

Untuk menggunakan API penyimpanan Azure guna mengakses tabel, tambahkan pernyataan include berikut ke bagian atas file C++:

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

Klien Azure Storage atau klien Azure Cosmos DB menggunakan string koneksi untuk menyimpan titik akhir dan kredensial untuk mengakses layanan manajemen data. Saat menjalankan aplikasi klien, Anda harus menyediakan string koneksi penyimpanan atau string koneksi Azure Cosmos DB dalam format yang sesuai.

Siapkan string koneksi Azure Storage

Contoh ini memperlihatkan cara mendeklarasikan bidang statis untuk menahan string koneksi Azure Storage:

// 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>"));

Gunakan nama akun Penyimpanan Anda untuk <your_storage_account>. Untuk <your_storage_account_key>, gunakan kunci akses untuk akun Storage yang tercantum di portal Microsoft Azure. Untuk informasi tentang akun Storage dan kunci akses, lihat Membuat akun penyimpanan.

Menyiapkan string koneksi Azure Cosmos DB

Contoh ini memperlihatkan cara mendeklarasikan bidang statis untuk menahan string koneksi Azure Cosmos DB:

// 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>"));

Gunakan nama akun Azure Cosmos DB Anda untuk <your_cosmos_db_account>. Masukkan kunci utama Anda untuk <your_cosmos_db_account_key>. Masukkan titik akhir yang tercantum di portal Microsoft Azure untuk <your_cosmos_db_endpoint>.

Untuk menguji aplikasi di komputer lokal berbasis Windows, Anda dapat menggunakan Azure Storage Emulator yang diinstal dengan Azure SDK. Storage Emulator adalah utilitas yang mensimulasikan layanan Azure Blob, Antrean, dan Tabel yang tersedia di mesin pengembangan lokal Anda. Contoh berikut menunjukkan bagaimana cara mendeklarasikan bidang statis untuk menahan string koneksi ke emulator penyimpanan lokal Anda:

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

Untuk memulai Azure Storage Emulator, dari desktop Windows, pilih tombol Mulai atau tombol Windows. Masukkan dan jalankan Microsoft Azure Storage Emulator. Untuk informasi selengkapnya, lihat Menggunakan Azure Storage Emulator untuk pengembangan dan pengujian.

Mengambil string koneksi Anda

Anda dapat menggunakan kelas cloud_storage_account untuk mewakili informasi akun penyimpanan Anda. Untuk mengambil informasi akun penyimpanan Anda dari string koneksi penyimpanan, gunakan metode parse.

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

Selanjutnya, dapatkan referensi ke kelas cloud_table_client. Kelas ini memungkinkan Anda mendapatkan objek referensi untuk tabel dan entitas yang disimpan dalam layanan penyimpanan Tabel. Kode berikut akan membuat objek cloud_table_client dengan menggunakan objek akun penyimpanan yang Anda ambil sebelumnya:

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

Membuat dan menambahkan entitas ke tabel

Buat tabel

Objek cloud_table_client memungkinkan Anda mendapatkan objek referensi untuk tabel dan entitas. Kode berikut membuat objek cloud_table_client dan menggunakannya untuk membuat tabel baru.

// 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();  

Menambahkan entitas pada tabel

Untuk menambahkan entitas ke tabel, buat objek table_entity baru dan teruskan ke table_operation::insert_entity. Kode berikut menggunakan nama depan pelanggan sebagai kunci baris dan nama belakang sebagai kunci partisi. Bersama-sama, kunci partisi dan baris entitas secara unik mengidentifikasi entitas dalam tabel. Entitas dengan kunci partisi yang sama dapat dikueri lebih cepat daripada entitas dengan kunci partisi yang berbeda. Menggunakan kunci partisi yang beragam memungkinkan skalabilitas operasi paralel yang lebih besar. Untuk informasi selengkapnya, lihat Daftar periksa performa dan skalabilitas penyimpanan Azure.

Kode berikut membuat contoh baru table_entity dengan beberapa data pelanggan untuk disimpan. Kode berikutnya akan memanggil table_operation::insert_entity untuk membuat objek table_operation guna menyisipkan entitas ke dalam tabel, dan mengaitkan entitas tabel baru. Akhirnya, kode akan memanggil metode execute pada objek cloud_table. table_operation baru mengirim permintaan ke layanan Tabel untuk memasukkan entitas pelanggan baru ke dalam tabel people.

// 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);

Menyisipkan batch entitas

Anda dapat memasukkan batch entitas ke layanan Tabel dalam satu operasi penulisan. Kode berikut akan membuat objek table_batch_operation, lalu menambahkan tiga operasi sisipkan ke objek tersebut. Setiap operasi sisipkan ditambahkan dengan membuat objek entitas baru, mengatur nilainya, lalu memanggil metode insert pada objek table_batch_operation untuk mengaitkan entitas dengan operasi sisipkan baru. Kemudian, kode akan memanggil cloud_table.execute untuk menjalankan operasi.

// 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);

Beberapa hal yang perlu diperhatikan pada operasi batch:

  • Anda dapat melakukan hingga 100 insert, delete, merge, replace, insert-or-merge, dan insert-or-replace operasi dalam kombinasi apa pun dalam satu batch.
  • Operasi batch dapat memiliki operasi mengambil, jika operasi tersebut adalah satu-satunya operasi dalam batch.
  • Semua entitas dalam satu operasi batch harus memiliki kunci partisi yang sama.
  • Operasi batch terbatas pada payload data 4-MB.

Membuat kueri dan mengubah entitas

Mengambil semua entitas dalam partisi

Untuk mengkueri tabel untuk semua entitas dalam partisi, gunakan objek table_query. Contoh kode berikut menentukan filter untuk entitas tempat Smith merupakan kunci partisi. Contoh ini akan mencetak bidang setiap entitas dalam hasil kueri ke konsol.

Catatan

Metode ini sekarang tidak didukung untuk C++ di Azure Cosmos DB.

// 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;
}  

Kueri dalam contoh ini mengembalikan semua entitas yang cocok dengan kriteria filter. Jika Anda memiliki tabel besar dan perlu sering mengunduh entitas tabel, sebaiknya simpan data Anda di blob penyimpanan Azure.

Mengambil berbagai entitas dalam partisi

Jika Anda tidak ingin mengkueri semua entitas dalam partisi, Anda bisa menentukan rentang. Gabungkan filter kunci partisi dengan filter kunci baris. Contoh kode berikut menggunakan dua filter untuk mendapatkan semua entitas dalam partisi Smith di mana kunci baris (nama depan) dimulai dengan huruf yang lebih lama dari E dalam alfabet, lalu mencetak hasil kueri.

Catatan

Metode ini sekarang tidak didukung untuk C++ di Azure Cosmos DB.

// 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;
}  

Mengambil satu entitas

Anda dapat menulis kueri untuk mengambil satu entitas tertentu. Kode berikut menggunakan table_operation::retrieve_entity untuk menentukan pelanggan Jeff Smith. Metode ini hanya mengembalikan satu entitas, bukan koleksi, dan nilai yang dikembalikan berada di table_result. Menentukan tombol partisi dan baris dalam kueri adalah cara tercepat untuk mengambil satu entitas dari layanan Tabel.

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;

Mengganti entitas

Untuk mengganti entitas, ambil dari layanan Tabel, ubah objek entitas, lalu simpan kembali perubahan ke layanan Tabel. Kode berikut mengubah nomor telepon dan alamat email pelanggan yang sudah ada. Sebagai ganti memanggil table_operation::insert_entity, kode ini akan menggunakan table_operation::replace_entity. Pendekatan ini menyebabkan entitas sepenuhnya diganti di server, kecuali entitas di server telah berubah sejak diambil. Jika telah diubah, operasi akan gagal. Kegagalan ini mencegah aplikasi Anda menimpa perubahan yang dilakukan antara pengambilan dan pembaruan oleh komponen lain. Penanganan yang tepat dari kegagalan ini adalah untuk mengambil entitas lagi, membuat perubahan Anda, jika masih valid, dan kemudian melakukan operasi table_operation::replace_entity lain.

// 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);

Menyisipkan atau mengganti entitas

table_operation::replace_entity operasi gagal jika entitas telah diubah sejak diambil dari server. Selain itu, Anda harus mengambil entitas dari server terlebih dahulu agar table_operation::replace_entity berhasil. Terkadang, Anda tidak tahu apakah entitas ada di server. Nilai saat ini yang disimpan di dalamnya tidak relevan, karena pembaruan Anda harus menimpa semuanya. Untuk mencapai hasil ini, gunakan operasi table_operation::insert_or_replace_entity. Operasi ini menyisipkan entitas jika tidak ada. Operasi ini menggantikan entitas jika ada. Dalam contoh kode berikut, entitas pelanggan untuk Jeff Smith masih diambil, tetapi kemudian disimpan kembali ke server dengan menggunakan table_operation::insert_or_replace_entity. Setiap pembaruan yang dibuat untuk entitas antara operasi pengambilan dan pembaruan akan ditimpa.

// 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);

Mengkueri subset properti entitas

Kueri ke tabel bisa mengambil hanya beberapa properti dari entitas. Kueri dalam kode berikut menggunakan metode table_query::set_select_columns untuk mengembalikan hanya alamat email entitas dalam tabel.

// 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;
}

Catatan

Mengkueri beberapa properti dari entitas adalah operasi yang lebih efisien daripada mengambil semua properti.

Menghapus konten

Menghapus entitas

Anda dapat menghapus entitas setelah mengambilnya. Setelah Anda mengambil entitas, panggil table_operation::delete_entity dengan entitas yang akan dihapus. Kemudian panggil metode cloud_table.execute. Kode berikut mengambil dan menghapus entitas dengan kunci partisi Smith dan kunci baris dari Jeff.

// 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);  

Menghapus tabel

Terakhir, contoh kode berikut menghapus tabel dari akun penyimpanan. Tabel yang telah dihapus tidak tersedia untuk dibuat ulang selama beberapa waktu setelah penghapusan.

// 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";
}

Pemecahan Masalah

Untuk Visual Studio Community Edition, jika proyek Anda mendapatkan kesalahan build karena menyertakan file storage_account.h dan table.h, hapus sakelar kompiler /permisif-:

  1. Di Penjelajah Solusi, klik kanan proyek Anda dan pilih Properti.
  2. Dalam kotak dialog Halaman Properti, perluas Properti Konfigurasi, perluas C/C++, dan pilih Bahasa.
  3. Atur Mode kesesuaian ke Tidak.

Langkah berikutnya

Explorer Microsoft Azure Storage adalah aplikasi mandiri gratis dari Microsoft yang memungkinkan Anda bekerja secara visual dengan data Azure Storage di Windows, macOS, dan Linux.

Ikuti tautan ini untuk mempelajari selengkapnya tentang Azure Storage dan API untuk Tabel di Azure Cosmos DB: