DataGrip 2023.3 Help

Quick start with DataGrip

This quick start guide will introduce you to the key concepts and help you with your first steps in DataGrip.

Also, you can check our introduction video that covers all major topics about the IDE: adding data sources, configuring connection options, working in the editor, and installing plugins.

Prerequisites

To complete this quick start guide, ensure that you have installed the following software:

Step 1. Create a new project

When you open DataGrip, you see the Welcome screen.

DataGrip displays the Welcome screen when no project is opened. For example, when you run DataGrip for the first time or when you close the only open project. From this screen, you can create a new project, open an existing project, or clone files from a Version Control System (VCS).

Creating a project

  1. In the Welcome screen, click the New Project button.

  2. In the Enter new project name field, type the name of your project.

  3. Click OK to create the project.

    New Project

After the project is created and opened, you will see an IDE interface with all tool windows hidden. Tool windows are tabs that are attached to the bottom and sides of the IDE window. You can rearrange and even detach them to use as separate windows, for example, on another monitor.

Step 2. Connect to a database

Depending on a database vendor (MySQL, PostgreSQL, Oracle, and so on), you need to create a corresponding data source to use it to connect to the database.

In this tutorial, we will use SQLite because, for other databases, you need a running instance of the database. It means that you need to install and configure them before creating a connection.

A database in SQLite is a single disk file. The file format is cross-platform. A database that is created on one machine can be copied and used on a different machine with a different architecture. DataGrip can create this file for you. So, all you need is to download drivers. The file default name is identifier.sqlite, but you can change it.

If you want to connect to other database management systems (DBMS), refer to the Data sources topic.

  1. To connect to the database, create a data source that will store your connection details. You can do this using one of the following ways:

    • From the main menu, navigate to File | New | Data Source | Other Data Source from URL and select SQLite.

    • In the Database Explorer ( View | Tool Windows | Database Explorer) , click the New icon (the New icon) in the toolbar. Navigate to Data Source Data Source | Other Data Source from URL and select SQLite.

    Create a new data source
  2. Check if there is a Download missing driver files link at the bottom of the connection settings area. Click this link to download drivers that are required to interact with a database. For a direct download link, refer to the JetBrains JDBC drivers page.

    Location for the downloaded JDBC drivers is the DataGrip configuration directory.

    The Download missing driver files link

    You can also use your drivers for the database instead of the provided ones. For more information about connecting to a database with your driver, refer to Add a user driver to an existing connection.

    If there is no Download missing driver files link, then you already have the required drivers.

  3. Specify the database connection details. Alternatively, paste the JDBC URL in the URL field.

    To create a new SQLite database, change the default identifier.sqlite name of the database, if needed. Alternatively, click the New button (the New button) and specify the name and location for your new database file.

  4. Ensure that the connection to the database can be established using the provided details. To do that, click the Test Connection link at the bottom of the connection details area.

    Test Connection link

    In case of any connection issues, refer to the Cannot connect to a database page.

  5. (Optional) By default, only the default >schema is introspected and available to work with. If you also want to work with other schemas, in the Schemas tab, select them for the introspection.

    Schemas tab of the Data Sources and Drivers dialog
  6. Click OK to create the data source.

As the data source is ready, you will see it in the Database Explorer.

Also, along with the data source, DataGrip creates a query console.

So, after connecting to a database, you can view its structure and start writing your queries to it right away.

Database Explorer, query console, and Files tool window

Step 3. Attach a directory with SQL scripts

To run SQL scripts, you can right-click the data source and select SQL Scripts | Run SQL script. Alternatively, you can attach a folder with these scripts to the Files tool window and run them from here.

For illustration purposes, we will use Sakila dump files. You can get them by cloning the dumps repository. Note that you need to install Git to clone the repository.

git clone https://github.com/DataGrip/dumps.git
  1. Navigate to View | Tool Windows | Files in the menu. Alternatively, press Alt+2.

  2. In the Files tool window, right-click any area and select Attach Directory to Project.

  3. Navigate to the directory that you want to attach. In our case, it is the dumps directory.

  4. Click OK.

Step 4. Run dump files

The dumps repository includes scripts that generate the structure of the Sakila database and scripts that add data to database objects. Let's run a script that generates objects in the main schema.

  1. In the Files tool window ( View | Tool Windows | Files) , navigate to the sqlite-sakila-db tree node.

  2. Expand sqlite-sakila-db tree node.

  3. Right-click the sqlite-sakila-schema.sql file and select Run 'sqlite-sakila-schema...'. Alternatively, press Control+Shift+F10.

  4. In the Target data source / schema table, click the Add button (The Add button) and select SQLite.

  5. Click Run.

Step 5. Write your code

As you work in the editor, DataGrip analyzes your code, searches for ways to optimize it, and detects potential and actual problems. The following list includes basic features and tools that might be useful for your code writing and increase your productivity:

Code completion

  • Suggestions for code completion appear as you type your code. DataGrip has two types of code completion:

    Basic code completion Control+Space helps you complete names of tables, routines, types, and keywords within the visibility scope. When you invoke code completion, DataGrip analyzes the context and suggests the choices that are reachable from the current caret position. By default, DataGrip displays the code completion popup automatically as you type.

    Smart code completion Control+Shift+Space filters the suggestion list and shows only the types applicable to the current context.

    The following animation shows the difference between basic and smart completion. Notice the number of variants that are suggested for different completion types

Generating code

  • DataGrip provides multiple ways to generate common code constructs and recurring elements, which helps you increase productivity. These can be either file templates used when creating a new file, custom or predefined live templates that are applied differently based on the context, various wrappers, or automatic pairing of characters.

    Go to Code | Generate Alt+Insert to open the popup menu with available constructs that you can generate.

    You can generate functions, procedures, views, and other database objects.

    To generate an object, press Alt+Insert and select the object that you want to generate.

Live templates

  • Use live templates to insert common constructs into your code, such as statements or definitions of database objects.

    The following video shows how you can use live templates.

    To expand a code snippet, type the corresponding template abbreviation and press Tab. Keep pressing Tab to jump from one variable in the template to the next one. Press Shift+Tab to move to the previous variable.

    To see the list of live templates, open settings Control+Alt+S and navigate to Editor | Live templates.

Inspections

  • In DataGrip, there is a set of code inspections that detect and correct abnormal code in your project before you compile it. The IDE can find and highlight various problems, locate dead code, find probable bugs, spelling problems, and improve the overall code structure.

    Inspections can scan your code in all project files or only in specific scopes (for example, only in production code or in modified files).

    Every inspection has a severity level — the extent to which a problem can affect your code. Severities are highlighted differently in the editor so that you can quickly distinguish between critical problems and less important things. DataGrip comes with a set of predefined severity levels and enables you to create your own.

    To see the list of inspections, open settings Control+Alt+S and navigate to Editor | Inspections. Disable some of them, or enable others, plus adjust the severity of each inspection. You decide whether it should be considered an error or just a warning.

    For example, the Redundant code in COALESCE call inspection reports all the arguments except for the first expression that does not evaluate to NULL.

    Redundant code in the COALESCE call

Intention actions

As you work in the editor, DataGrip analyzes your code, searches for ways to optimize it, and detects potential and actual problems.

As soon as the IDE finds a way to alter your code, it displays a yellow bulb icon yellow bulb icon in the editor next to the current line. By clicking this icon, you can view intention actions available in the current context. Intention actions cover a wide range of situations from warnings to optimization suggestions. You can view the full list of intentions and customize them in the Settings dialog Control+Alt+S.

To see the list of intention actions, open settings Control+Alt+S and navigate to Editor | Intentions.

  1. Click the light bulb icon (or press Alt+Enter) to open the list of suggestions.

  2. Select an action from the list and press Enter.

    For example, you can use an intention action in the INSERT statement to create a table with valid field types:

Video tutorials

This video covers various topics about DataGrip. The video length is 40 minutes, but you can click time codes on the Youtube page to see the topic that you are interested in. For more information about time codes and topics, refer to the description section at youtube.com.

Last modified: 12 December 2023