> For the complete documentation index, see [llms.txt](https://codemash.gitbook.io/codemash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codemash.gitbook.io/codemash/cloud/database/aggregates/delete.md).

# Delete an aggregate

Delete a saved aggregate no app runs any more.

**Where:** Database → Aggregates → click the **ID** → **Delete** · `/projects/<project>/db/aggregates/<aggregateId>/edit`

## Before you start

* You need `database:delete` on the aggregates of its schema.
* Search your apps for the id first: an app that still runs a deleted aggregate gets an error.

## Steps

1. Open **Database → Aggregates** and click the aggregate's id.
2. Press **Delete** at the top right. The dialog **Delete Confirmation** asks *Are you sure you want to delete?*

   <figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-af583342604ace16bf05b0fed9598a7917ce34f0%2Faggregates-delete-1.png?alt=media" alt="Editing aggregate Old stock report behind the dialog Delete Confirmation: Are you sure you want to delete? with Cancel and Delete"><figcaption><p>The confirmation dialog.</p></figcaption></figure>
3. Press **Delete**. **Cancel** keeps the aggregate.

## Result

Cloud goes back to the list and the aggregate is gone. A schema the aggregate started from or joined can now be deleted, if nothing else uses it.

<figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-4ab95c9502f43383434127df5141be20a27713ad%2Faggregates-list-1.png?alt=media" alt="Aggregates list with only Books per genre left"><figcaption><p>The list after the delete.</p></figcaption></figure>

## Change or remove it later

A deleted aggregate cannot be restored. [Create it again](/codemash/cloud/database/aggregates/new.md); it gets a new id, so update the apps that run it.

## Do it from code

```ts
await norbix.hub.database.deleteDatabaseAggregate({ id, schemaId: 'sch_7lPCzWonEvTQsheGDCaKq' });
```

```sh
norbix hub database aggregate delete --id maggr_2DbvQjVHZ2NTsPBaLyc4eT --schemaId sch_7lPCzWonEvTQsheGDCaKq --yes
```

The client setup is on the [Database page](/codemash/cloud/database.md#use-it-from-code). API: [Delete Database Aggregate](/codemash/api-reference/database/aggregates/delete-database-aggregate.md)
