Back to JetBrains

DataGrip Overview, Part 3: SQL Editor

JetBrainsOctober 14, 20267m
In a Nutshell

DataGrip's SQL editor provides extensive productivity features including live templates for rapid statement creation, intelligent auto-completion based on schema relationships, and real-time error detection for issues like unresolved references or mismatched insert columns. Code modifications are streamlined through shortcuts like Shift+F6 for renaming, Alt+Enter for intention actions, and multi-cursor editing for bulk changes. The editor supports customizable formatting, context-aware templates that leverage object types, and editor splitting for side-by-side comparison.

AI-Generated Notes

These notes were generated by AI and may contain inaccuracies.

Typing SEL and pressing the tab key quickly creates a select statement, then allows selection of the desired table. This demonstrates live templates, which are ready-made snippets for commonly used cases. Pressing command J displays a list of all available snippets, with template shortcuts on the left side of the window and descriptions on the right side.

The INS direct template creates a simple insert statement. The template is called first, then the table is selected, suggested columns are accepted, and values are entered. Live templates can be edited in the live templates settings by navigating to the SQL section, which displays a list of all templates.

The SEL template can be updated to use the variable {$END$}, which determines where to place the writing cursor after the query is created. Placing this variable directly after the alternate tag (wildcard) results in the cursor being positioned after the alt tag when the live template is called. Templates are highly customizable through these settings.

Right-clicking on an object displays several options for creating a new query using that object within the SQL scripts menu. The most common method creates a SELECT statement for the table. This mechanism is called direct context templates, allowing creation of common statements directly from the database explorer while taking into account the object type (such as table or view) and the SQL dialect of the current data source.

Live context templates are edited in Settings, Editor, Live Templates. Unlike ordinary live templates that rely solely on cursor position in the editor, context templates use special template variables: DB_OBJECT_NAME and DB_COLUMNS.

Code auto-completion is the first and most important aspect of software assistance. Writing J prompts the development environment to anticipate a join statement, and DataGrip completes the entire statement. This functionality works through introspection, as DataGrip is aware of schema relationships.

Auto-complete supports shortcuts such as typing OB for "order by" and FID as an abbreviation for the "film ID" column. While using wildcards is not usually considered best practice, it provides the opportunity to learn the Alt and Enter shortcut, which shows different intention actions.

The intention actions menu provides the option to expand the list of columns. The "qualify identifier" procedure works even with multiple columns at once. DataGrip is intelligent enough to qualify columns in case of conflicts.

DataGrip analyzes queries before they run and highlights errors immediately. Deleting an alias when needed triggers a warning about ambiguity. Unresolved references are highlighted in red, such as when changing the reference "actor" to "actor_1", which DataGrip does not recognize as an object in the database. The columns of unknown tables are also highlighted.

By analyzing insert statements, DataGrip can alert when the number of columns to insert does not match the target location. An additional check warns when about to delete all data from a table. Many other checks are continuously being improved to detect potential problems in queries in advance.

Shift F6 is the shortcut for renaming objects. Calling it on an alias allows assigning a new name, and all uses of that alias are also renamed. The Alt Enter shortcut always suggests options for modifying SQL code, including converting a query into one containing a subquery, which can then be converted into a common table expression.

Command, Alt, and L formats queries. Settings, then Editor, then Code Style contains several settings for each specific phrase to customize the formatter according to needs.

Multiple cursors are often the most efficient way to modify SQL code. To use this feature, place the cursor in the desired location and press Alt twice while holding it down, then add new indicators using the arrow keys. Changes can then be made to multiple lines as if editing only one line.

Multiple indicators can also be placed using the text search feature by searching for the desired word, selecting "Select all results," and then editing the lines. Other useful text editing shortcuts include Command and Backspace to delete the entire line, Command and D to repeat the line, and Command and Slash to add a comment to the line.

DataGrip allows splitting any editor to have two editors working side-by-side. Right-clicking on the tab and choosing "Split Right" or "Split Down" accomplishes this.

Keep JetBrains in your library

Save the videos and channels worth coming back to, and find them again in one place.