How to Create an Uninstaller for Your Drupal Module

Add something like the following to your module's .install file, where mymodule is the name of the module.

/**
* Implementation of hook_uninstall.
*/

function mymodule_uninstall() {
        switch ($GLOBALS['db_type']) {
                case 'mysql':
                case 'mysqli':
    case 'pgsql':
      variable_del('mymodule_var_one');
      variable_del('mymodule_var_two');
      variable_del('mymodule_var_three');
                        break;
        }
        drupal_set_message(t('All references to the MyModule module have been removed from the database.'));
} // function hook_uninstall()

variable_del() clears the variables cache table too, so you don't have to worry about that.