DBeaver Documentation


SQL Generation


DBeaver provides the functionality to automatically generate SQL scripts, streamlining your SQL scripting process. This feature is accessible from two main areas within the application: the Data Editor and the Database Navigator.

Generate SQL Scripts

From Data Editor

You can automatically generate SQL statements based on the selected database object in the Data Editor. To do this:

  1. Right-click on the selected database object.

  2. Click Generate SQL.

  3. Choose one of the SQL commands from the context menu that appears.

  4. The generated SQL statement will appear in a new window for you to review and copy.

From Database Navigator

You can also generate SQL scripts directly from the Database Navigator. To do this:

  1. Right-click on a database object in the Database Navigator.

  2. Navigate to Generate SQL.

  3. Choose the type of SQL statement you want to generate.

  4. The generated SQL statement will appear in a new window for you to review and copy.

Additional Settings

In the opened window, you have options to further customize your generated SQL script.

Option Description
Use the fully qualified names Includes [schema name].[table name] in table references.
Compact SQL Condenses SQL script into a single line.
Separate foreign keys Isolates foreign key definitions in the script.
Exclude auto-generated columns Omits automatically generated columns from the script.
Use custom data/time format Customizes date and time formats in the script.
Show comments Adds comments to the script for readability.
Show permissions Includes permission settings in the script.
Show full DDL Adds a comprehensive Data Definition Language section to the script.
Show partitions DDL Incorporates partitioning information into the DDL section of the script.
Use explicit type cast Adds explicit type casting for SQL values in the script.
Add CAST to parameters definition Adds explicit data type conversion to parameter definitions in the script.

Note: The availability of these settings may vary depending on the database you are using.

Read Data in SQL Console

DBeaver streamlines your database navigation tasks with its capability to automatically generate and execute SELECT statements. This functionality is especially useful when you are working in the Database Navigator.

To read data in SQL Console:

  1. Navigate to the Database Navigator and identify the database object you want to read.
  2. Right-click on the chosen database object.
  3. Select Read data in SQL console.
  4. A SQL console opens, executing the query and fetching all relevant rows.

Save Your Scripts

DBeaver offers two methods for saving the SQL queries you've executed:

  • Save As: Accessible through the SQL console's context menu, this option allows you to save the SQL query after specifying a file name.

  • Save as Script: Also found in the SQL console's context menu, this function saves the query immediately as a numbered script, without prompting you for a file name.

Tip: Pressing Ctrl+S will transform the SQL console into a SQL editor, enabling more extensive modifications.