Handy Drush DB commands

I use these commands to see drupal data, but not often enough to remember them when I need them.

drush sqlq --database=default "show tables"
drush sqlq --database=default "describe tablename"
drush sqlq --database=default "SELECT * FROM tablename"
drush sqlq --database=default "TRUNCATE TABLE tablename"

Get the number of rows in a table:

drush sqlq --database=default "SELECT COUNT(*) FROM tablename"

For dealing with update hooks:

Get the current hook_update_N for a site.

drush sqlq "SELECT schema_version from system where name = 'module_name';"

Change the current hook_update_N for a site. Particularly useful on dev sites where you are testing an hook_update_N for a module or Feature.

drush  sqlq "UPDATE system SET schema_version=7011 WHERE name = 'module_name';"

Not a db command, but still very handy for outputting a node object to a text file.

drush ev 'print_r(node_load(25901));' >> ~/Desktop/node.txt