Refactoring and Finding usages

The IDE correctly resolves all table and column references over your SQL files and allows you to rename any symbol and its usages easily.

SQL refactoring

Introduce alias

This is one of the most important SQL refactorings. Get your stopwatch ready and see how much time this saves you! Put the caret on the table name press Alt+EnterIntroduce table alias.

Extract sub-query as CTE

Another refactoring to make your SQL neater and less nested. It’s placed under Refactor | Extract | Subquery as CTE. But we think it’s easier to use Find Action. Or assign a shortcut!

Renaming

Aliases and variables

When you rename the symbol inside SQL, it is also renamed in all usages inside your code. To rename, press Shift+F6

Database objects

If it is an existing object like table or column, it will be renamed in the datasource as well.

Find usages

Usages highlighting

DataGrip highlights the usages of particular objects in the current context. Note, that it is not just text search, the IDE understands what the objects are that are used in the statement

Find usages inside source codes

DataGrip lets you find the usages of objects inside the source code of other objects. For instance, you can learn in which stored procedures, functions or views your table is used. As usual, press Alt+F7 on the table name or call it from the context menu.