Adding sql script to add column to existing d b table

filename: mysql4-upgrade-1.1.1-1.1.2.php

<?php
 
$installer = $this;
$installer->startSetup();
 
$connection = $installer->getConnection();
 
$tableName = $installer->getTable('your_table_name');
$column = 'newcolumn_id';
$comment = 'Newcolumn ID';
 
if (!$connection->tableColumnExists($tableName, $column)) {
    $connection->addColumn($tableName, $column, array(
        "type" => Varien_Db_Ddl_Table::TYPE_INTEGER,
        "nullable" => true,
        "length" => 10,
        "after" => "customer_id",
        "comment" => $comment
    ));
}
 
$installer->endSetup();

Leave a Reply