Search code examples
mysqlalter-table

Alter table in mysql, add column error 1064 (42000)?


I am trying to add column in mysql table but following error thrown.

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ALTER TABLE cm_article ADD COLUMN active INT NOT NULL DEFAULT '0' AFTER description'

My Sql Statement is: ALTER TABLE cm_article ADD COLUMN active INT NOT NULL DEFAULT '0' AFTER description;


Solution

  • There are two different types of quotation marks in MySQL. You need to use ` for column names and ' for strings. Since you have used ' for the filename column the query parser got confused.

    ALTER TABLE `cm_article` ADD COLUMN `active` INT NOT NULL DEFAULT '0' AFTER `description` ;