Free Android CakePHP GMaps Articles by Bali Web Design

January 29, 2012

How to add first column on existing table mysql

Filed under: query tips — admin @ 11:42 pm

I am encountering problem to add increment column on existing table mysql database. The existing table has some columns except increment column. So now i need increment column, but i don’t want to put this column at the end of the table, this is not look good for me.

So i check to mysql manual and found interesting sintak, beside use AFTER column syntax, there is FIRST syntax. So the query is look like this

ALTER TABLE table_name ADD COLUMN `ID` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT First,
ADD PRIMARY KEY (`ID`);

I hope this article can help you to add first column on existing table mysql database server.