How do I add more members to my ENUM-type column in MySQL?

前端 未结 7 1346
自闭症患者
自闭症患者 2020-12-02 08:05

The MySQL reference manual does not provide a clearcut example on how to do this.

I have an ENUM-type column of country names that I need to add more countries to. W

7条回答
  •  天涯浪人
    2020-12-02 08:18

    Here is another way...

    It adds "others" to the enum definition of the column "rtipo" of the table "firmas".

    set @new_enum = 'others';
    set @table_name = 'firmas';
    set @column_name = 'rtipo';
    select column_type into @tmp from information_schema.columns 
      where table_name = @table_name and column_name=@column_name;
    set @tmp = insert(@tmp, instr(@tmp,')'), 0, concat(',\'', @new_enum, '\'') );
    set @tmp = concat('alter table ', @table_name, ' modify ', @column_name, ' ', @tmp);
    prepare stmt from @tmp;
    execute stmt;
    deallocate prepare stmt;
    

提交回复
热议问题