MySQL - How to increase varchar size of an existing column in a database without breaking existing data?

后端 未结 7 2051
渐次进展
渐次进展 2020-12-13 05:32

I have a column that is currently varchar(100) and I want to make it 10000.

is it as simple as

alter table table_name set          


        
相关标签:
7条回答
  • 2020-12-13 06:08

    For me this has worked-

    ALTER TABLE table_name ALTER COLUMN column_name VARCHAR(50)

    0 讨论(0)
  • 2020-12-13 06:08

    use this syntax: alter table table_name modify column col_name varchar (10000);

    0 讨论(0)
  • 2020-12-13 06:11

    I'd like explain the different alter table syntaxes - See the MySQL documentation

    For adding/removing defaults on a column:

    ALTER TABLE table_name
    ALTER COLUMN col_name {SET DEFAULT literal | DROP DEFAULT}
    

    For renaming a column, changing it's data type and optionally changing the column order:

    ALTER TABLE table_name
    CHANGE [COLUMN] old_col_name new_col_name column_definition
    [FIRST|AFTER col_name]
    

    For changing a column's data type and optionally changing the column order:

    ALTER TABLE table_name
    MODIFY [COLUMN] col_name column_definition
    [FIRST | AFTER col_name]
    
    0 讨论(0)
  • 2020-12-13 06:18

    For me worked this one:

    ALTER TABLE tablename MODIFY fieldname VARCHAR(128) NOT NULL;

    0 讨论(0)
  • 2020-12-13 06:31

    I am using mysql and below syntax worked well for me,

    ALTER TABLE table_name MODIFY col_name VARCHAR(12);
    
    0 讨论(0)
  • 2020-12-13 06:31

    I normally use this statement:

    ALTER TABLE `table_name`
      CHANGE COLUMN `col_name` `col_name` VARCHAR(10000);
    

    But, I think SET will work too, never have tried it. :)

    0 讨论(0)
提交回复
热议问题