# Drop Indexes Example

> Example showing how to drop indexes by name on any database from custom code with g.sys.system.dropIndexes.

Source: https://docs.apimaker.dev/v1/examples/sys/system/dropIndexes.html

`g.sys.system.dropIndexes` calls the [drop indexes system API](https://docs.apimaker.dev/v1/docs/apis-all/system-apis/system-generated-drop-indexes-api.html) from your code, whatever the settings of that API say about HTTP callers.

### Drop indexes System API

Drop indexes of a table by name using global object 'g'. A name the table does not have is `NOT_FOUND`, not an error, so the call can run again.

```ts
const results = await g.sys.system.dropIndexes({
    instance: 'mysql8',
    database: 'inventory',
    table: 'orders',
    indexes: ['am_ix_orders_customer_id_status_3f9a1c', 'old_idx_status'],
    ifExists: true,         // default : a missing index is NOT_FOUND
    continueOnError: true,  // default : one refused drop does not stop the others
});
// results[0] : { status: 'DROPPED', fields: ['customer_id', 'status'], ... }
// results[1] : { status: 'NOT_FOUND', message: 'The index "old_idx_status" does not exist.', ... }
```

- Several tables at once : give a list of such objects, the results come back in one flat list.
- `instance: "crm::acme"` drops in the database of the tenant `acme` of the multi-tenant instance `crm`.

## Related

- [Drop indexes system API](https://docs.apimaker.dev/v1/docs/apis-all/system-apis/system-generated-drop-indexes-api.html) · [All system APIs from code](https://docs.apimaker.dev/v1/examples/sys/system/system.html) · [The global object g](https://docs.apimaker.dev/v1/docs/pre-defined-terms/global-object-g.html)
