Working with Database Consoles
Database consoles let you compose and execute SQL statements for databases defined in PyCharm as data sources. They also let you analyze and modify the retrieved data.
The following standardized and DBMS vendor-specific SQL dialects are supported: DB2, Derby, H2, HSQLDB, MySQL, Oracle, Oracle SQL*Plus, PostgreSQL, SQL Server, SQL92, SQLite, and Sybase.
One database console is created for a data source automatically when a data source is created. If necessary, you can create additional consoles.
Database consoles are persistent: they are stored as SQL files.
A database console created in one of your projects can then be accessed from any other project.
Creating a database console
When you create a DB data source, one database console for that data source is created automatically. If necessary, you can create additional consoles.
Select the data source of interest or any node within it, and do one of the following:
Opening a database console
The Database tool window lets you open only default consoles, i.e. the ones that were created by PyCharm automatically.
- Click on the title bar if the toolbar is hidden.
- Click on the toolbar if the toolbar is shown.
- Select Open Console from the context menu.
- Press Ctrl+Shift+F10.
- Double-click the console.
- Select from the main menu.
- Select Jump to Source from the context menu.
- Press F4.
Viewing and modifying console settings
Before actually starting to use a console, you may want to take a look at the console settings and adjust them to your needs.
- To access these settings, click on the toolbar of the input pane or on the toolbar of the Database Console tool window. (Alternatively, Ctrl+Alt+S .)
As a result, the Database page of the Settings / Preferences dialog will open.
Changing the SQL dialect
By default, the SQL dialect used in a console is defined by the DBMS of an associated data source. If for some reason you want to use a different dialect:
- Right-click the editing area of the input pane, select Change Dialect (<CurrentDialect>), and select the necessary dialect.
In addition to particular dialects, also the following option is available:
Closing a console
- Click (Ctrl+Shift+F4) to close the Database Console tool window.
- Click on the editor tab (Ctrl+F4) to close the input pane.
Managing database consoles
To manage your database consoles, use the Scratches view of the Project tool window.
The view shows the existing database consoles (represented by SQL files) grouped by your data sources (shown as folders). The default consoles (the ones that were created by PyCharm automatically) have the same names as the corresponding data sources.
- Create new consoles. Select the target data source or a node within it, and do one of the following:
- Rename your consoles. When a new console is created, it has the name of the data source with a number at the end, e.g.
MySQL_1. If you want to give a console a more descriptive name, select the console and do one of the following:
Then, specify a new name in the dialog that opens.
- Save your console files in arbitrary directories. Select the console and then choose (F5). Specify the file name and location in the dialog that opens.
- Group your consoles. This is done by creating folders and then dragging your consoles into those folders.
- Open your consoles. Select the consoles of interest and do one of the following:
- View the history of changes for your consoles. Select from the main menu or from the context menu.
- Delete individual consoles and groups of consoles. Use , Delete from the context menu or Delete on the keyboard.