Search code examples
mysqlalter

in mysql, add the column after the other column if exists


how can it?

I found it for check column exists

(
SELECT 1 FROM Information_schema.columns
WHERE table_schema = 'db' 
AND table_name = 'table' 
AND column_name = 'the other column'
)

and add the column after the other column

ALTER TABLE 'table' ADD 'the column' VARCHAR(14) DEFAULT NULL AFTER 'the other column'

Solution

  • give the name of the db in which the table exists:-

    ALTER TABLE db.table ADD the_column VARCHAR(14) DEFAULT NULL AFTER the_other_column
    

    It worked for me try this and let me know where it is failing