# Indexes

A database index is a structure used to speed up locating and accessing operations in a database table. By using indexes, you decrease the number of disk accesses that are required when a query is processed. You can create indexes for one or more columns of a database table.

Indexes (       ![Index](https://resources.jetbrains.com.cn/help/img/idea/2026.2/database-plugin.icons.expui.index.svg)      ) can be found in the   Database   tool window   .

* For the reference on other node and object icons, refer to the [Data sources and their elements](database-tool-window.html#icons-for-data-sources-and-their-elements) chapter of [Database tool window](database-tool-window.html) topic.

* For the table column icons, refer to the [Possible icon combinations for columns](database-tool-window.html#possible-icon-combinations-for-columns) chapter.

* Hide, sort, filter, and group tree objects using the tree objects view options in the [View Options](database-tool-window.html#view_options) menu.

![Indexes in Database](https://resources.jetbrains.com.cn/help/img/idea/2026.2/database_object_index.png)

For MongoDB, indexes are supported for database versions 4.0 and later. Currently, only the abilities to display and drop indexes are supported.

Procedure: Create an index

1. In the   Database   tool window ,    expand the data source tree until the nodes of     columns.

2. Right-click the         table or column node and select `New |        Index` .

3. In the   dialog that opens, enter the name of your index in the Name field.

4. In the Columns pane, click the Add button (![the Add button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg)).

5. In the Column Name field, specify the name of the column that you want to add to the index.

6. In the Preview pane, you can view and change the generated SQL code.

7. Click OK to  add your index    .

![Create an index](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_create_index.png)

## Productivity tips

Procedure: Modify templates for generated index and key names

When you create indexes, and primary and foreign key constraints, their default names are generated according to corresponding templates. For a primary key, for example, the template is `{table}_{columns}_pk`.

* To view and modify these templates, open the settings `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) and navigate to `Editor | Code Style | SQL | General`. Click the Code Generation tab.

The templates can contain variables and text. When you generate a name, the specified text is reproduced literally. For example, when you apply the `{table}_pk` template in the `actor` table, the generated name of the primary key will be `actor_pk`.

To see information about variables and their usage, click a field and press `Ctrl+Q` (Windows), `F1` (macOS), `⌃ J` (IntelliJ IDEA Classic (macOS)), `⌘ I` (macOS System Shortcuts), `Ctrl+Q` (XWin), `Ctrl+Q` (GNOME), `Ctrl+Q` (KDE), `Ctrl+Q` (Emacs), `Ctrl+Q` (Sublime Text), `Ctrl+Q` (Sublime Text (macOS)), `Ctrl+Q` (NetBeans), `Ctrl+K, I` (Visual Studio), `⌘ K, I` (Visual Studio (macOS)), `Alt+Middle-Click` (Eclipse), `⌥ Middle-Click` (Eclipse (macOS)).

`{unique?u:}` checks if the index is unique and inserts the corresponding sequence of characters. If the index is unique, the template generates a name with the sequence of characters specified between `?` and `:`. For the `{unique?u:}` template, it is `u`. If the index is not unique, the sequence between `:` and `}` is inserted. For the `{unique?u:}` template, it is nothing.

Example

You have the `persons` table with columns `FirstName` and `LastName`. The `{table}_{columns}_{unique?u:}index` template generates the following name for the not unique index: `persons_FirstName_LastName_index`.

![Modify templates          for generated index and key names](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_modify_templates_for_indexes_and_keys.png)

### Reference

[Create and Modify dialog](create-and-modify-dialogs.html#objects_editor)    [Possible icon combinations for columns](database-tool-window.html#possible-icon-combinations-for-columns) [Data sources and their elements](database-tool-window.html#icons-for-data-sources-and-their-elements)

### Related

[Primary keys](primary-keys.html) [Foreign keys](foreign-keys.html)

### Tool Windows

[Database tool window](database-tool-window.html)

### Navigation

### Language and Framework-Specific Guidelines

[Database Tools and SQL](relational-databases.html)

