Top 9 SQL Features of DataGrip You Have to Know
DataGrip is a universal tool for dealing with databases. It supports PostgreSQL, MySQL, SQL Server, Oracle, and many other databases.
One of the most important activities for anyone working with databases is writing SQL. Built on IntelliJ Platform, DataGrip makes coding an enjoyable experience by automating repetitive tasks: as an SQL developer, you probably have many!
Let’s have a closer look at some of the nice SQL-related perks inside DataGrip.
1. Live Templates
DataGrip has code snippets called Live Templates. Use them to generate repetitive parts of SQL code.
There are some pre-built snippets for the most common tasks. Every live template has its own abbreviation — just type the abbreviation and then press Tab to fill in the rest of the code. For example, sel can be used for SELECT * FROM, while ins will provide the INSERT statement. Look at the Live Templates in action:
It is even possible to create custom templates for even greater efficiency. To do this go to Settings | Editor | Live Templates.
2. Introduce alias
This SQL refactoring is arguably one of the most important. Get your stopwatch ready as you are about to see how much time this saves you! Put the caret on the table name and press Alt+Enter (Opt+Enter for macOS) → Introduce table alias.
3. Expand wildcard
Since using wildcards is not recommended in many cases, DataGrip can expand it to list all the columns of the table for you. In the event of conflicts, identifiers will be qualified with the table or alias names. JOINs are also respected!
4. Postfix completion
This type of code completion is especially useful when real life doesn’t match the logic of how the code should be written. The best example is the SELECT statement: you need to think about the table you want to select fields from, and then you can decide which particular fields to select. Postfix completion lets you choose which order you do your coding.
An example would be if you type table_name.afrom you will get a list of all the table’s columns. Or, typing identifier.cast will generate the casting code for you.
5. Multiple carets
Multiple cursors can be an efficient way to modify code. Especially in SQL, where similar rows are often used. To do this in DataGrip, press Ctrl (Opt for macOS) twice and hold it, then place new cursors with the arrow keys.
There is the option to place cursors everywhere matches have been found. Invoke Select All Occurrences by Shift+Ctrl+Alt+J (Ctrl+Cmd+G for macOS) when the caret is on the word you want.
Did you notice? The clipboard is also multiline!
6. Inline renaming
When you rename an object inside SQL, it also renames all the other usages of it inside your code. To rename, press Shift+F6.
7. Abbreviation completion
Databases often have names with the same prefixes or first words which makes the normal kind of code completion not very useful: you may need to type the whole word to define a particular object. Abbreviation completion will save you here!
If you have names in camelCase or objects-with-hyphenated-names, just use the first letters of the words – it’s all you need, the rest will be completed with the suggestion.
The same for keywords: ob works for ORDER BY.
8. Code formatting
You can have your SQL code formatted automatically, based on flexible user-defined code styles. Don’t spend time formatting legacy code – let DataGrip do it for you with a single shortcut Ctrl+Alt+L (Cmd+Opt+L for macOS)!
Adjust the code style in Settings | Editor | Code Style | SQL where you can, for example, define whether you capitalize keywords or not. Your style can be shared with your colleagues, so you are all working to the same standard.
9. Toggling comments
Toggle with your comments to make it easier to manage your code. Choose what type of comments you want to use – block or line-by-line (if it’s supported by your SQL dialect).
To comment with a line comment press Ctrl+/ (Cmd+/ for macOS).
To comment with a block comment press Ctrl+Alt+/ (Ctrl+Opt+/ for macOS).
That’s it! We hope this article was useful for existing DataGrip users and also helps those who have never tried DataGrip learn a little bit about it.
Your DataGrip Team
The Drive to Develop
Subscribe to Blog updates
Introspection Level Auto-Selection
Back in 2015, I was the only DataGrip team member working on database introspectors. Since then, several of my teammates have followed suit with their own introspectors for various database management systems (DBMSs). The Oracle introspector, however, remains solely my project. The Oracle introsp…
DataGrip 2023.3 EAP 2 is Out!
Hello, DataGrip community! The second Early Access Program version for DataGrip 2023.3 is here. If you want to try the new features before the official release, this is for you! Introspection scheduler It's now possible to set an introspection interval for each data source. Support for mat…
DataGrip 2023.3 EAP is Open
Hello! We’re starting our 2023.3 Early Access Program (EAP) and, as usual, we invite you to try the latest features and improvements we’re adding to DataGrip ahead of the official release. Let’s take a look at what’s inside the first EAP build. : Introspection level defaults DataGrip …
DataGrip 2023.2: New UI with toolbar icons in the header, AI Assistant, time zones in the data editor, support for Redis Cluster
DataGrip 2023.2 is out!Here’s a sneak peek at what it has to offer. For a detailed description of this update, please visit our What’s New page. User Interface New UI: The toolbar icons have been moved to the header Improved main toolbar customization Light theme with light …