MySQL 修改int型別為bigint SQL語句拼接

haoge0205發表於2020-03-24

SELECT

  CONCAT(

    "alter table ",

    TABLE_SCHEMA,

    ".",

    TABLE_NAME,

    " modify ",

    COLUMN_NAME,

    " bigint(20)",

  IF

    ( IS_NULLABLE = 'NO', " NOT NULL", "" ),

  IF

    ( EXTRA = "", "", " AUTO_INCREMENT" ),

  IF

    ( COLUMN_DEFAULT IS  NULL, "", CONCAT( " DEFAULT ", COLUMN_DEFAULT ) ),

  IF

    ( COLUMN_COMMENT = "", "", CONCAT( " COMMENT '", COLUMN_COMMENT, "'" ) ),

    ";" 

) AS alter_sql 

FROM

  information_schema.COLUMNS 

WHERE

  ( COLUMN_NAME = 'orderid' OR COLUMN_NAME = 'order_id' ) 

  AND DATA_TYPE = 'int';


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28939273/viewspace-2682362/,如需轉載,請註明出處,否則將追究法律責任。

相關文章