Is there a module that lists which tables are created, owned or modified by a particular module?

I need something that can show me what tables are created or modified by when new modules are installed.


Building on what Ursula said about Drupal using hook_schema() for all modules to define their tables, there is a module called Schema which gives you a full list of all tables and their associated modules.

If you are a module developer, this is an incredibly handy module since it allows you to first create the table manually in your database, and when you load up the Schema page, it will generate the code for the table definition for you.

| improve this answer | |
  • It's a good idea to mention that creation of tables outside schema is also possible, and that ignoring tables created that way is customary in Durpal. – Mołot Oct 18 '13 at 23:47
  • I'm confused about what you mean. Are you saying that some modules will arbitrarily create tables by other methods than hook_schema()? If so, then that's really bad practice and highly discouraged. But if you're saying that it's possible for a developer or site administrator to add their own custom table to the drupal database, then yes that's possible... For instance, on one project I've been working on, I have a few very large "reference" tables which contain data that is considered read-only. These tables are created by an SQL file any time I need to put them on a new development server. – hargobind Oct 19 '13 at 12:13
  • @hargobind thanks for pointing to the schema module, it's indeed handy. I amended my answer to include it. – Ursula Oct 19 '13 at 16:59

Since Drupal 7, tables should get created by modules using hook_schema(), because these tables will also get removed when uninstalling the module.

You can find these tables by executing the code below, or by using the Schema module (https://drupal.org/project/schema):

$schema = drupal_get_schema(Null,TRUE);// Get List Of all tables. 
  ksort($schema);// Sort Ascending
  foreach($schema as $table => $value){

All well written modules should create tables only using hook_schema, and should not alter tables in other modules.

If you suspect that other tables got changed, you can find this in the .install file for each module. Look for the database layer calls like db_add_field or even db_create_table.

For a list of all these, consult the Drupal documentation: https://api.drupal.org/api/drupal/includes!database!database.inc/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.