DataGrip tips and tricks (part 1)
2 min read

DataGrip tips and tricks (part 1)

DataGrip tips and tricks (part 1)

DataGrip is an excellent tool by JetBrains for developers who work with SQL databases. This post will be the first of a series of posts about some of my favorite DataGrip features and tricks. Let's start!

Live templates

It is common to have to repeat some queries or some statements. You can save time by saving them in the Live Templates section (Settings Editor Live Templates) and calling them by typing their abbreviation in the editor. They are live because they are not simple snippets, but you can also configure internal variables and apply functions to them.

DataGrip - Live template

You can find more info here.

Custom aliases

Usually, we always use the same aliases or even have an internal convention in our team. However, you can avoid writing them every time by configuring Custom aliases (Editor General Code Completion).

After configuring the alias, you can retrieve it just by pressing Ctrl+Space after the original name.

DataGrip - Custom alias

Abbreviation completion

If your database has table names in camel case or hyphenated, you can type its initials + the Tab key, and the name will be autocompleted.

This feature also works with functions or keywords, so if you would like to use the TO_DATE function or the ORDER BY keyword, you can type 'td' or 'ob'.

Inline renaming

Eager to rename an alias but lazy to do it on each line? Just press Shift+F6, and it will be renamed everywhere :)

DataGrip - Inline renaming

Export results to SQL Inserts/Updates or HTML

DataGrip allows you to export, both to the clipboard and a file, in many formats.

My favorite exports are two. The first is the export to SQL Inserts / Updates, since it is a quick way to make a "backup" of the records to be modified or deleted. The second is the export to HTML. In the latter case, if the records are few, you can copy the result to the clipboard and then paste it into other applications such as JIRA or an email message.

You can find the export options at the top right of the results section (Services tool window).

Bonus: Additional useful shortcuts

Ctrl+Shift+V Paste from clipboard history
Ctrl+E Recent files
Ctrl+Shift+E Recent locations
Ctrl+D Duplicate line
Ctrl+X Cut line
Ctrl+Alt+L Reformat code
Ctrl+Shift+A Find any action

You can find all the shortcuts here!

And you can edit the shortcuts by going to Settings Keymap.