1-- ALTER TABLE tbl_name ADD COLUMN column_name column_definition
2-- [FIRST|AFTER existing_column];
3ALTER TABLE office ADD COLUMN phone VARCHAR(200) DEFAULT '000' AFTER name;
4ALTER TABLE office ADD COLUMN flag INT(1) FIRST;
5ALTER TABLE office ADD COLUMN last_col INT(2); -- Last column is default position
6-- ↓ Test it (Fiddle)
1SELECT CONCAT('ALTER TABLE ', table_schema,'.', TABLE_NAME,' ADD COLUMN `hash` VARCHAR(50) NULL DEFAULT UUID() AFTER ', first_column, ';') AS ddl
2
3FROM (
4
5 SELECT
6 (
7 SELECT `COLUMN_NAME`
8 FROM `INFORMATION_SCHEMA`.`COLUMNS`
9 WHERE `TABLE_SCHEMA`=t.TABLE_SCHEMA AND `TABLE_NAME`=t.TABLE_NAME
10 LIMIT 1
11 ) AS 'first_column',
12 t.*
13 FROM
14 information_schema.tables t
15 WHERE table_schema = 'your_table_name' AND table_type = 'base table'
16
17) AS x;