Create a DDL data source using SQL files
DDL data source is a virtual view of a database structure based on SQL files that contain data definition language statements (DDL statements). You can reference all tables, columns and other objects defined in such files in the editor. Diagrams are also supported.
To create a DDL data source using SQL files, create new SQL files that contain the required statements to define database objects and data for the data source.
For more information about DDL data sources, refer to the DDL data sources topic.
In the 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)
);
For inserting the
CREATE TABLE
statement, there is a predefined pattern. Press Ctrl0J and select the patterntab - new table definition
.Type the table name
family
.To switch from
family
tocol
, press Tab. Replacecol
withmember_id
.Type the remaining part of the table definition.
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) .
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.
Create an SQL file.
let's add this simple
INSERT
statement into the file:insert into family (member_id, name, relation) values (1, 'Chloe', 'mother');
Add the
INSERT
statement by selecting the corresponding predefined pattern: Ctrl0J |ins - insert rows into a table
.Select the table name
family
.Select the list of column names
member_id, name, relation
.When specifying the values, press Ctrl0P (View | Parameter Info) to see the information about the value types.
![Define data for the DDL data source in the SQL file Define data for the DDL data source in the SQL file](https://resources.jetbrains.com/help/img/idea/2024.3/db_work_with_ddl_define_data.png)
Thanks for your feedback!