# classname_delete

> This function deletes a database object (referenced by its class handle).

### Prototype

>         MCO_RET	classname_delete(	/*IN*/ classname * handle );

### Arguments

handle | The address of a variable of type ``class handle``

### Description

This function will remove the object referenced by handle, and all of the object’s versions, from the database. Hash and tree index entries, if any, will also be removed.

### Return Codes

MCO_S_OK | The instance was deleted successfully
MCO_E_ACCESS | The transaction handle is `MCO_READ_ONLY`
MCO_E_TRANSACT | Transaction is in error state
MCO_E_DELETED | This object has been deleted
MCO_E_NOMEM | Database memory allocation error
MCO_ERR_OBJECT_HANDLE | Invalid object handle
MCO_ERR_TRN | Error in the enclosing transaction

### Example

> The following code snippets demonstrate how `classname_delete()` is used to delete a database object.

        Snippet from schema file:

        class Record
        {
            uint4 key;

            hash <key> hkey;
        };

        Application snippet:

        int find_delete(mco_db_h db, int hkey_val)
        {
            MCO_RET rc;
            mco_trans_h t;
            Record obj;

            rc = mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t);
            if ( MCO_S_OK == rc )
            {
                rc = Record_hkey_find(t, hkey_val, &obj);
                if ( MCO_S_OK == rc )
                 {
                    rc = Record_delete(&obj);

                }
                rc = mco_trans_commit(t);
            }
        }

Related Topics