search

Home  >  Q&A  >  body text

mysql - 求 alter column , change column , modify column 区别

在Mysql 里边 Alter TABLE 子选项中 alter column , change column , modify column 有什么区别?

如果有一张大表,执行不同的选项会有什么差异?
求解答

PHP中文网PHP中文网2786 days ago681

reply all(1)I'll reply

  • 阿神

    阿神2017-04-17 11:26:20

    ALTER COLUMN: Set or remove the default value of a column (very fast operation)
    Example:

    alter table film alter column rental_duration set default 5;  
    alter table film alter column rental_duration drop default;
    

    CHANGE COLUMN: Column renaming, column type change and column position movement
    Example:

    ALTER TABLE MyTable CHANGE COLUMN foo bar VARCHAR(32) NOT NULL FIRST;  
    ALTER TABLE MyTable CHANGE COLUMN foo bar VARCHAR(32) NOT NULL AFTER baz; 
    

    MODIFY COLUMN: Except that the column cannot be renamed, it does the same job as CHANGE COLUMN
    Example:

    ALTER TABLE MyTable MODIFY COLUMN foo VARCHAR(32) NOT NULL AFTER baz;
    

    Quoted from: http://blog.csdn.net/dba_waterbin/article/details/17884549

    reply
    0
  • Cancelreply