MySQL: How to alter varchar(255) UNIQUE column to UNIQUE Text NOT NULL?

前端 未结 3 576
北恋
北恋 2021-01-13 06:02

The current column is a VARCHAR(255) NOT NULL, so how do I change it to TEXT NOT NULL?

NOTE: The column intended to be changed its property type is a UNIQUE KEY comb

3条回答
  •  再見小時候
    2021-01-13 06:29

    alter table your_table
    modify column your_column text not null;
    

    for unique key

    alter table your_table 
    add unique index your_index_name (your_column(your_length));
    

    your_length = allow up 1000 bytes

    The maximum key length is 1000 bytes. This can also be changed by changing the source and recompiling. For the case of a key longer than 250 bytes, a larger key block size than the default of 1024 bytes is used


    Both length (description + another column can not longer than 1000),so

    alter table your_table 
    add unique index your_index_name (description(800), another_column(200));
    

提交回复
热议问题