# Use projections (/docs/guides/operate/projections)



Use projections [#use-projections]

A projection stores another layout for a table. It uses extra storage and
increases insert and merge work.

Before you begin [#before-you-begin]

* Use the `analytics` database. Create it with the [database API](/docs/reference/api/databases#post-v1databases) if it does not exist.
* Use an `events` table with `tenant` and `event_time` paths.

1\. Add a projection [#1-add-a-projection]

Add a layout that stores counts by tenant.

```sql test
ALTER TABLE events ADD PROJECTION by_tenant (SELECT `__raw_data.tenant`, count() GROUP BY `__raw_data.tenant`)
```

2\. Materialize the projection [#2-materialize-the-projection]

Populate the projection for existing table parts.

```sql test
ALTER TABLE events MATERIALIZE PROJECTION by_tenant
```

3\. Inspect projection parts [#3-inspect-projection-parts]

Check whether table parts contain the projection.

```sql test
SELECT count() FROM system.projection_parts WHERE database = currentDatabase() AND table = 'events' AND name = 'by_tenant'
```

4\. Check projection mutations [#4-check-projection-mutations]

Repeat this query until it returns `0`.

```sql test
SELECT count() FROM system.mutations WHERE database = currentDatabase() AND table = 'events' AND command LIKE '%PROJECTION by_tenant%' AND is_done = 0
```

5\. Clear projection data [#5-clear-projection-data]

Clear stored projection data and keep its definition.

```sql test
ALTER TABLE events CLEAR PROJECTION by_tenant
```

Repeat the mutation query until it returns `0`.

6\. Drop the projection [#6-drop-the-projection]

Drop the projection when you no longer need its layout.

```sql test
ALTER TABLE events DROP PROJECTION by_tenant
```

Next steps [#next-steps]

* [Projection concepts](/docs/concepts/projections)
* [ALTER TABLE statements](/docs/reference/sql/statements/alter-table)
