How to Create table in Magento from sql Script

magento

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Example for Creating table in Magento</title>
</head>
<body>
<?php

$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();
$installer->run("
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`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
");
$installer->endSetup();

?>
</body>
</html>
Posted in Uncategorized