# Change a sorting key (/docs/guides/operate/change-sorting-key)



Change a sorting key [#change-a-sorting-key]

Use a table sorting key when you know which paths your queries filter or sort.

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\. Set the sorting key [#1-set-the-sorting-key]

Choose paths that match the table's query patterns.

```sql test
ALTER TABLE events MODIFY ORDER BY (tenant, event_time)
```

2\. Inspect the table [#2-inspect-the-table]

Read the sorting-key expression from `system.tables`.

```sql test
SELECT sorting_key FROM system.tables WHERE database = currentDatabase() AND name = 'events'
```

Check the result [#check-the-result]

The `sorting_key` value contains `tenant` and `event_time`.

Next steps [#next-steps]

* [Sorting-key concepts](/docs/concepts/sorting-keys)
* [Optimize queries](/docs/guides/query/optimize-queries)
* [ALTER TABLE statements](/docs/reference/sql/statements/alter-table)
