How to Create table in Magento from sql Script


In MAGENTO We can create new table with the sql file with the new updated version.
New Version should be defined into the config file , so that magento can understand which is the latest version.
Please paste below code into your sql file and it will create sample table for you :-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Example for Creating table in Magento</title>

$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
DROP TABLE IF EXISTS {$collection->getTable('test/test')};
CREATE TABLE {$collection->getTable('test/test')} (
  `test_id` int(11) unsigned NOT NULL auto_increment,
  `test_name` varchar(255) NOT NULL default '',
  `test_description` text NOT NULL default '',
  `test_logo` varchar(255) NULL default '',
  `created_time` datetime NOT NULL DEFAULT '0000:00:00 00:00:00',
  `updated_time` datetime NOT NULL DEFAULT '0000:00:00 00:00:00',
	  `status` smallint(6) NOT NULL DEFAULT '1',
  PRIMARY KEY (`test_id`)

Posted in Uncategorized