Tuesday, July 30, 2013

How to create the table using module?

/**
* Implements hook_schema().
*/


function module_name_schema() {
$schema['module_name'] = array(
‘fields’ => array(
‘type’ => array(‘type’ => ‘varchar’, ‘length’ => 15, ‘not null’ => TRUE, ‘default’ =>
‘node’),
‘id’ => array(‘type’ => ‘int’, ‘unsigned’ => TRUE, ‘not null’ => TRUE, ‘default’ => 0),
‘module_name’ => array(‘type’ => ‘varchar’, ‘length’ => 255, ‘not null’ => TRUE,
‘default’ => ”)
),
‘primary key’ => array(‘type’, ‘id’),
);
return $schema;
}


/**
* Implements hook_uninstall().
*/


function module_name_uninstall() {
// Clear variables
variable_del(‘module_name_default’);
}

Use db_drop_table method in install file to drop the table using module.

No comments:

Post a Comment