If i’ve the following database
CREATE TABLE `my_table` (
`year` text,
`event` text
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `my_table` VALUES ('2011', 'john');
INSERT INTO `my_table` VALUES ('2011', 'dave');
INSERT INTO `my_table` VALUES ('2010', 'hany');
My question is how to add id auto_increment so that it can be
INSERT INTO `my_table` VALUES (1, '2011', 'john');
INSERT INTO `my_table` VALUES (2, '2011', 'dave');
INSERT INTO `my_table` VALUES (3, '2010', 'hany');
I’ve tired this but failed
$q1 = "ALTER TABLE `my_table` ADD COLUMN `id` int(3) NOT NULL auto_increment";
mysql_query($q1) or die(mysql_error()." at row ".__LINE__);
and given me error Incorrect table definition so how to do it correctly.
you should add first the
COLUMNthenINDEXand thenAUTO_INCREMENTOR 2 queries: