Skip to main content

Remove data

Overview

This guide provides instructions to to delete data from a multi-index table.

Procedure

Complete the following steps to implement a del action which deletes an user object, identified by its account name, from the multi-index table.

1. Find The User You Want To Delete

Use the multi-index find( ) method to locate the user object you want to delete. The targeted user is searched based on its account name.

[[inery::action]] void multi_index_example::del( name user ) {
// check if the user already exists
auto itr = datatable.find(user.value);
}

2. Delete The User If Found

Check to see if the user exists and use erase( ) method to delete the row from table. Otherwise print an informational message and return.

[[inery::action]] void multi_index_example::del( name user ) {
// check if the user already exists
auto itr = datatable.find(user.value);
+ if ( itr == datatable.end() ) {
+ printf("User does not exist in table, nothing to delete");
+ return;
+ }

+ datatable.erase( itr );
}

Summary

In conclusion, the above instructions show how to delete data from a multi-index table.