📜  在第一列mysql代码示例之后向所有表添加列

📅  最后修改于: 2022-03-11 15:05:27.460000             🧑  作者: Mango

代码示例2
SELECT CONCAT('ALTER TABLE ', table_schema,'.', TABLE_NAME,' ADD COLUMN `hash` VARCHAR(50) NULL DEFAULT UUID() AFTER ', first_column, ';') AS ddl

FROM (

    SELECT
        (
            SELECT `COLUMN_NAME`
            FROM `INFORMATION_SCHEMA`.`COLUMNS`
            WHERE `TABLE_SCHEMA`=t.TABLE_SCHEMA AND `TABLE_NAME`=t.TABLE_NAME
            LIMIT 1
        ) AS 'first_column',
        t.*
    FROM
    information_schema.tables t
    WHERE table_schema = 'your_table_name' AND table_type = 'base table'
    
) AS x;