CiviCRM: sysadmin hacks

Deleting tables from the database

This is usually necessary when resetting a database, without dropping/re-creating the whole database, only delete all tables and views.

BE VERY CAREFUL WHEN USING THIS.

Delete only CiviCRM Views:

echo "SHOW FULL TABLES IN [my-db-name] WHERE TABLE_TYPE LIKE 'VIEW'" | drush sqlc | awk '{print $1}' | grep -v Tables_in | awk '{print "drop view " $1 ";"}'  | drush sqlc

Delete only CiviCRM tables:

echo 'show tables' | drush sqlc | grep civicrm | gawk -v NOFOREIGNCHECK='SET FOREIGN_KEY_CHECKS=0;' 'BEGIN {print NOFOREIGNCHECK}{print "drop table " $1 ";"}'  | drush sqlc

Drop ALL tables (Drupal and CiviCRM, if they are in the same database):

echo 'show tables' | drush sqlc | grep -v Tables_in | gawk -v NOFOREIGNCHECK='SET FOREIGN_KEY_CHECKS=0;' 'BEGIN {print NOFOREIGNCHECK}{print "drop table " $1 ";"}'  | drush sqlc

Notes