Skip to content
>_ SQL Query Builder

Writing Queries ​

The Query Builder supports not only SELECT queries but all SQL commands (DCL, DDL, DML), provided your user privileges allow it.

πŸ“Œ Your user permissions may restrict certain actions.

Create a New Query ​

To create a new query, click the Menu icon in the toolbar and choose:

  • Private Query: Visible to you only.
  • Global Query: Accessible to all admininistrators.

CREATE PRIVATE VS GLOBAL QUERY

WP Data Access - Create New Private QueryWP Data Access - Create New Global Query

Open an Existing Query ​

Click the Menu icon and select Open. A dialog will appear showing your saved private and global queries. Select the query you need to load. You can also open multiple queries at once using the provided checkboxes.

OPEN PRIVATE VS GLOBAL QUERY

WP Data Access - Open Private QueryWP Data Access - Open Global Query

Multiple SQL Commands ​

Separate multiple SQL statements with a line containing only a forward slash: /.

✨ Example ​

sql
drop table if exists x
/

create table x
(x int)
/

insert into x values(1)
/

insert into x values(2)
/

update x
set x = x + 100
/

select *
from x
/

Multiple Data Sets ​

Each SQL command opens in its own tab and displays its respective results or response.

WP Data Access - Multiple Responses

User-Defined Variables and Dynamic Queries ​

You can use user-defined variables to build dynamic SQL queries in the Query Builder.

✨ Example ​

sql
SET @column = "columnname"
/

SET @table = "tablename"
/

SET @select = CONCAT("SELECT ", @column, " FROM ", @table)
/

PREPARE stmt FROM @select
/

EXECUTE stmt
/

Query Parameters ​

To run or schedule a query with different values, you can use query parameters. Click the Add Parameters button and define a name and value for each parameter in the dialog. Use the + button to add your parameter. Click DONE when you are ready.

WP Data Access - Query Parameters

WordPress Table Protection ​

To keep your site safe, WordPress core tables are protected by default. Generally, you cannot DROP, ALTER, or TRUNCATE these tables. This behavior can be changed in the Query Builder Settings, accessible via the Query Builder main menu.

CHANGE WORDPRESS CORE TABLE PROTECTION

WP Data Access - Query Builder SettingsWP Data Access - WordPress Code Table Protection

Database Response ​

A scrollable table below the editor displays your query results. You can export this data to CSV, JSON, or XML.

View Raw Output ​

Click the SERVER RESPONSE tab to view the raw database output. The output is shown in a read-only JSON format.

Save Query ​

Click the Save Query icon or use the Ctrl+S (or Cmd+S on Mac) keyboard shortcut from within the editor to save your query.

WP Data Access - Save Query

Query Context Menu ​

Each query tab has a context menu, accessible via the three-dots icon at the end of the tab toolbar. This menu provides quick access to essential actions for managing your queries efficiently:

  • Copy a query to a different name or scope.
  • Rename your query for easier identification.
  • Delete a query you no longer need.
  • Schedule execution at defined intervals.
  • Load from file to import saved SQL commands.
  • Save to file for local backups or version control.
  • Copy to clipboard to paste your SQL elsewhere.
  • Close the query tab when you’re done.

These options help streamline your workflow and offer added flexibility for managing SQL tasks directly from the WordPress dashboard.

WP Data Access - Query Builder - Query Menu

Execution Time ​

To display the SQL execution time (shown in parentheses after each result), add the following lines to your wp-config.php file:

php
define( 'WP_DEBUG_LOG', true );
define( 'SAVEQUERIES', true );