SQL Editor

The SQL Editor in DBCode enables you to create, execute, and manage SQL queries within `.sql` files in Visual Studio Code, featuring syntax highlighting, code formatting, intelligent autocomplete, and seamless connection switching.

The SQL Editor in DBCode provides a powerful environment for working with .sql files, making it easy to write, execute, and manage SQL queries. It offers intelligent features like syntax highlighting, code formatting, autocomplete, and the ability to quickly switch database connections, ensuring a seamless and efficient workflow.

Using the SQL Editor

1. Create or Open a .sql File

  • From the Connections Panel:
    Open the Connections pane in DBCode, select your desired database connection, and click the Create New SQL File icon next to the database.

    Creating a new SQL file from the Connections panel
    Create SQL files directly from your database connection
  • From the File Menu:
    Alternatively, click on the File menu in Visual Studio Code, select New File.

    Creating a new file from the File menu
    Use the standard VS Code File menu to create a new file

    Then set the file name and save it with a .sql extension, and start working.

    Saving a new SQL file
    Save your file with a .sql extension

2. Write SQL Code

  • Begin typing SQL commands to take advantage of syntax highlighting, autocomplete, and error detection.

  • Use features like Autocomplete and Inline Completion for enhanced coding assistance.

3. Format Code

  • Format Entire Document:
    Right-click anywhere in the file and choose Format Document, or use the shortcut Alt+Shift+F.

    Formatting SQL code with right-click menu
    Format your entire SQL document with a single click
  • Format Selected Code:
    Highlight a code block, right-click, and select Format Selection, or use Ctrl+K Ctrl+F (Windows/Linux) or Cmd+K Cmd+F (macOS).

    Formatting selected code
    Format only the selected portion of your SQL code

4. Switch Database Connections

  • Use the dropdown in the code lens at the top of the editor or the status bar to change the active database connection.

  • Easily switch between databases without closing or reopening the file.

    Switching database connections
    Change the active database connection seamlessly

5. Execute Queries and View Results

  • Run Selected Queries:
    Highlight a query and click Execute Selection from the toolbar or right-click and select Execute Selection with DBCode.

  • Run All Queries:
    Click the Execute Query icon at the top-right corner or press Ctrl+Enter to run all queries in the file.

    Executing SQL queries
    Run your SQL queries with ease
  • View Results: Query results are displayed in the DBCode Results Panel at the bottom of the editor.

    Viewing query results
    Check your query results in the Results Panel

Result Tab Behavior

By default, each query execution creates a new result tab. This allows you to compare results across multiple queries. However, if you’ve created charts or customized your view, you may want to preserve those settings when re-running a query.

Refresh Result in Place

Hold Shift while executing (Shift+Cmd+Enter on macOS, Shift+Windows+Enter on Windows/Linux) to update the last result tab instead of creating a new one. This preserves any chart configuration you’ve created.

Single-Tab Mode

When using single-tab mode (dbcode.maxTabs set to 1), the behavior is inverted - refresh-in-place becomes the default, and holding Shift creates a new tab instead.

Behavior Matrix

ModeShift KeyResult
Multi-tabNot pressedNew tab created
Multi-tabPressedLast tab refreshed (chart preserved)
Single-tabNot pressedLast tab refreshed (chart preserved)
Single-tabPressedNew tab created

Note: Pinned tabs are never replaced. If the last tab is pinned, a new tab will always be created.

Stacked Results

When executing multiple SQL statements, each result set typically opens in its own tab. Hold Alt while executing (Alt+Cmd+Enter on macOS, Alt+Windows+Enter on Windows/Linux) to stack all result sets into a single tab with collapsible sections.

Stacked result tabs feature:

  • Collapsible sections - Each result set has a header showing the SQL preview, row count, and column count. Click to expand or collapse.
  • Resizable sections - Drag the dividers between sections to adjust their heights.
  • Synchronized scrolling - Click the link icon in the first section header to synchronize horizontal scrolling across all grids.
  • Close sections - Click the X icon to remove a section. Closing the last section closes the tab.
  • Connection indicators - Sections from different connections show a colored left border matching the connection color.

You can also stack existing result tabs by:

  • Drag and drop - Drag one result tab onto another to stack them together.
  • Multi-select - Hold Ctrl (Windows/Linux) or Cmd (macOS) and click multiple tabs, then right-click and select Stack with….
  • Context menu - Right-click on a result tab and select Stack with… to choose another tab to stack with.

6. Save and Reuse Queries

  • Save your .sql file with comments and code for future use by going to File > Save in the menu bar.

    Saving SQL files
    Save your SQL files for future use

Benefits of the SQL Editor

  • Flexible Connection Switching: Effortlessly toggle between database connections within a single file.

  • Enhanced Efficiency: Advanced features like autocomplete, syntax highlighting, and formatting speed up the query-writing process.

  • Integrated Workflow: Easily manage and view results within the same editor, ensuring a smooth SQL development experience.

DBCode’s SQL Editor brings an intuitive and feature-rich experience to managing .sql files in Visual Studio Code, empowering users to write and execute SQL commands efficiently while maintaining organized workflows.