0

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'
ParkDyel
  • 262
  • 2
  • 4
  • 19

1 Answers1

2

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

vinay chhabra
  • 587
  • 3
  • 7
  • I will run this code to each database had a different structure, but I want to add the column only if had a specific column. – ParkDyel Aug 29 '18 at 03:31