RCBian
RCBian

Reputation: 1080

Unable to add Column to table in mysql

I am trying to add a column to a table.To do so I am trying

ALTER TABLE requirements Modify COLUMN parent_id int(11);

but when I try to execute this query mysql does not respond for long.So each time I have to kill the query.

I have created the table using

CREATE TABLE requirements (requirement_id smallint(6) NOT NULL AUTO_INCREMENT,
    product_id smallint(6) NOT NULL, 
    name varchar(255) CHARACTERSET latin1 NOT NULL DEFAULT '', 
    PRIMARY KEY (requirement_id), 
    UNIQUE KEY requirement_product_id_name_idx (product_id,name), 
    UNIQUE KEY requirement_product_idx (requirement_id,product_id), 
    KEY requirement_name_idx_v2 (name) )
    ENGINE=InnoDB
    AUTO_INCREMENT=7365
    DEFAULT CHARSET=utf8;

Please help me know why I am not able to execute the Alter table query.I am new to database is there something wrong with my alter table query.

Upvotes: 0

Views: 1132

Answers (1)

Rahul Tripathi
Rahul Tripathi

Reputation: 172378

According to your table defintion parent_id seems to be a new column which you want to add so your query should be to add the column not modify.

Try this:

alter table requirements add column parent_id int(11);

SQL FIDDLE DEMO

On a side note:

There needs to be a space between CHARACTERSET here

name varchar(255) CHARACTERSET latin1 NOT NULL DEFAULT '', 

should be

name varchar(255) CHARACTER SET latin1 NOT NULL DEFAULT '', 

Upvotes: 1

Related Questions