Every data table in Moodle has one common element: the first field is an integer field called id
. This field is a unique field that serves as the Primary Key for every table. It also serves as the Foreign Key to any other data table that contains a reference to that table.
Although this may seem excessive to some database programmers, as there are often other fields that can serve as unique references, this is a core rule to Moodle database programming that should never be broken; Moodle code depends on it! And if you use Moodle's database XML schema to validate your table, it is required.
The XML schema defines other requirements and restrictions—for example, naming conventions such as:
A table name can be no longer than 28 characters
Field names can be no longer than 30 characters
The remainder of the database structure requirements is maintained by agreement only. These can always be found at http://docs.moodle.org/en/Development:Database.
Your table character set...