DataGrip 2022.2 Help

How to work with the DDL data source

Step 1. Define a table in an SQL file

In the Files tool window (View | Tool Windows | Files), right-click a directory and select New | SQL File. Specify a name for the SQL file.

Open the SQL file and define the following table structure in our file:

CREATE TABLE family ( member_id INT NOT NULL, name VARCHAR(50), relation VARCHAR(50) );
  1. For inserting the CREATE TABLE statement, there is a predefined pattern. Press Ctrl+J and select the pattern tab - new table definition.

    025dbe create table

    Here is the result:

    026dbe create table result

  2. Type the table name family.

    027dbe table name changed
  3. To switch from family to col, press Tab. Replace col with member_id.

    028dbe column name changed
  4. Type the remaining part of the table definition.

    030dbe table defined

Step 2. Create a DDL data source from the SQL file

To create a table from the SQL file, drag the SQL file with the defined table to the Database Explorer (View | Tool Windows | Database Explorer).

Create a data source from the SQL file

Step 3. Define data for the data source

Now we are going to create an SQL file for adding data to the table. On Step 2, the SQL file was defined as a data source, the names of the table and of its columns as well as the info about corresponding data types are now available in the editor.

  1. Create an SQL file.

    Create a file

    Let us add this simple INSERT statement into the file:

    insert into family (member_id, name, relation) values (1, 'Chloe', 'mother');

  2. Add the INSERT statement by selecting the corresponding predefined pattern: Ctrl+J | ins - insert rows into a table.

    the Insert statement
  3. Select the table name family.

    Paste the table name
  4. Select the list of column names member_id, name, relation.

    Insert column names
  5. When specifying the values, press Ctrl+P (View | Parameter Info) to see the information about the value types.

    Insert parameter values
Last modified: 05 October 2021