Skip to content

drupal db query

Paulo Maia Carvalho edited this page May 20, 2026 · 1 revision

drupal-db-query

Run a SQL query against the Drupal database via Drush.

Usage

/drupal-db-query SELECT COUNT(*) FROM node_field_data
/drupal-db-query SELECT nid, title FROM node_field_data WHERE status = 1 LIMIT 10

What it does

Passes the query to drush sql:query and returns the result as a table in the chat.

Examples

Count published nodes:

SELECT COUNT(*) FROM node_field_data WHERE status = 1

List users:

SELECT uid, name, mail FROM users_field_data WHERE uid > 0

Check for broken aliases:

SELECT source, alias FROM path_alias WHERE status = 1 LIMIT 20

Find large watchdog entries:

SELECT type, COUNT(*) as count FROM watchdog GROUP BY type ORDER BY count DESC

Notes

  • Read-only queries are safe to run freely. Destructive queries (UPDATE, DELETE, DROP) are executed immediately without additional confirmation — be careful.
  • Table names use Drupal's default prefix (none by default). If your project uses a table prefix, include it in the query.
  • Results are truncated at ~50 rows in the chat output. For larger result sets, export with /drupal-db-export and query the dump.

Related skills

Clone this wiki locally