Which database schema should I use? I want to create a custom voting module to learn how to write a module. The vote table will contain four fields (id, title, vote_up, vote_down).
Should I create a new table? If I create a new database table, how do I keep the relationship with the node being voted?
If you want to create a voting module you should look into Voting API, it's an API module that offers common functions and database storage for voting modules to use.

However, since this is a learning excercise, you might want to do it all yourself, in this case:


Use hook_schema() to define your database schema (the example on the documentation page is pretty self-explanatory!)
In Drupal 6 you need to manually specify which schema to install so implement hook_install() and hook_uninstall():




function mymodule_install() {
  drupal_install_schema('mymodule');
}

function mymodule_uninstall() {
  drupal_uninstall_schema('mymodule');
}


An example of a hook_schema might look like this:

/**
 * Implementation of hook_schema()
 */
  function mymodule_schema() {
    $schema['mymodule_votes'] = array(
      'description' =&gt; 'Your schema',
      'fields' =&gt; array(
        'vid' =&gt; array(
          'description' =&gt; 'vote id',
          'type'        =&gt; 'serial',
          'unsigned'    =&gt; TRUE,
          'not null'    =&gt; TRUE,
        ),
        'nid' =&gt; array(
          'description' =&gt; 'node id',
          'type'        =&gt; 'int',
          'unsigned'    =&gt; TRUE,
          'not null'    =&gt; TRUE,
        ),
        'vote_up' =&gt; array(
          'description' =&gt; 'number of votes up',
          'type'        =&gt; 'int',
          'unsigned'    =&gt; TRUE,
          'not null'    =&gt; TRUE,
          'default'     =&gt; 0
        ),
        'vote_down' =&gt; array(
          'description' =&gt; 'number of votes down',
          'type'        =&gt; 'int',
          'unsigned'    =&gt; TRUE,
          'not null'    =&gt; TRUE,
          'default'     =&gt; 0
        ),
      ),
      'primary key'     =&gt; array('vid'),
      'indexes'         =&gt; array('node id' =&gt; array('nid'))
    );
    return $schema;
  }