Development:Database schema introduction
The Moodle database has around 200 tables, and can be quite daunting at first sight. The good news is that you don't have to understand it all at once. For example, there are eight tables called forum_somthing. If you are interested in the forum module, then obviously you need to understand these tables, and the places they link into core tables. But if you are not interested in the forum module, you can forget about them. The same is true of each activity module.
Once you take out the tables for each activity module in this way, and similarly take out the tables belonging to the enrolment plugins, question types, etc. You are left with about 50 core tables. But the good news is that even here they break down into groups that mostly you can understand together, or ignore. This page lists the core database tables in these groups. Later, it would be good to add more detailed documentation explaining some of these groups.
The database structure is defined, edited and upgraded using the XMLDB system.
Automatically generated documentation
The install.xml files that define Moodle's database structure (are supposed to) contain comments on each table and database field, to document their purpose.
From Moodle 2.0 onwards, you can view this documentation in HTML format by going to Administration -> Development -> XMLDB editor and then clicking on the [Doc] links.
Configuration
- config
- config_plugins
Users and their profiles
- user
- user_info_category
- user_info_field
- user_info_data
- user_lastaccess
- this is separated from the user table for performance reasons
- user_preferences
- user_private_key
The roles and capabilites system
- role
- capabilites
- context
- a context is a scope in Moodle, for example the whole system, a course, a particular activity. The type is given by contextlevel, and depending on context level, instanceid points to one of a number of different tables.
- role_allow_assign
- which roles can assign which other roles
- role_allow_override
- which roles can override which other roles
- role_assignments
- which users are assigned which roles in which contexts
- role_capabilities
- the permission for each capability in either a role definition (if contextid points to the system context) or a role override (if contextid points to some other context)
- role_context_levels
- the context levels at which each role can be assigned. (Moodle 2.0 onwards.)
- role_names
- used to implement the feature where roles can be given different names in different courses (or, more gererally, contexts)
- role_sortorder
The following diagram shows the tables with their columns and the relationships between them, and other tables in Moodle.
Courses and their organisation into categories
- course
- course_categories
- course_display
- course_meta
- course_request
Activities and their arrangement within courses
- modules
- course_allowed_modules
- course_modules
- course_sections
See also the tables belonging to particular activity modules. For example forum_*, quiz_*, etc.
Groups and groupings
- groups
- groups_members
- groupings
- groupings_groups
The logging system
- log
- log_display
Blocks system
- block
- block_instance
- block_pinned
Some particular blocks also have their own database tables. For example block_rss_client.
Events
- event_*
Backup and restore
- backup_config
- backup_courses
- backup_files
- backup_ids
- backup_log
Statistics
- stats_daily
- stats_monthly
- stats_user_daily
- stats_user_monthly
- stats_user_weekly
- stats_weekly
Tags
- tag_*
Gradebook
- grade_*
Question bank and question engine
- question
- question_answers
- question_attempts
- question_categories
- question_sessions
- question_states
See also the tables for individual question types, which all start question_.
Messaging system
- message_*
Moodle Network
- mnet_*
Caching
- cache_*
Miscellaneous
- scale
- scale_history
- sessions2
- timezone
- post
See also
- Development:Database_Schema - some automatically generated diagrams.
- Development:XMLDB_Documentation - the XMLDB system used to define, edit, and update the database structure.