Menu

How to delete data from a multi index table

Preconditions

To delete data from a multi index table follow the steps below:

  1. Make use of the multi index table iterator to find out if the data exists
[[eosio::action]] void multi_index_example::del( name user ) {
  // check if the user already exists
  auto itr = testtab.find(user.value);
}
  1. If the data exists use the delete method to delete the row from table
[[eosio::action]] void multi_index_example::del( name user ) {
  // check if the user already exists
  auto itr = testtab.find(user.value);
+  if ( itr == testtab.end() ) {
+    printf("user does not exist in table, nothing to delete" );
+    return;
+  }

+  testtab.erase( itr );
}
Full example location

A full example project demonstrating the instantiation and usage of multi index table can be found here.