zoukankan      html  css  js  c++  java
  • Modify column Vs change column

    引言

    I know, we can not rename a column using modify column syntax,but can change column syntax.

    My question is: what is the main usage of modify syntax?

    For example,

    alter table tablename change col1 col1 int(10) not null
    

    instead of

    alter table tablename modify col1 int(10) not null
    

    Edited

    Question replaced

    What is the main usage of modify syntax?

    Above question was replaced by below

    Why we have to use change column instead of modify column?

    解释

    CHANGE COLUMN If you have already created your MySQL database, and decide after the fact that one of your columns is named incorrectly, you don't need to remove it and make a replacement, you can simply rename it using change column.

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

    MODIFY COLUMN This command does everything CHANGE COLUMN can, but without renaming the column.You can use the modify SQL command if you need to resize a column in MySQL. By doing this you can allow more or less characters than before. You can't rename a column using modify and other

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

    Note : ALTER TABLE is used for altering a table means to change column name, size, drop column. CHANGE COLUMN and MODIFY COLUMN commands cannot be used without help of ALTER TABLE command.


    更多精彩文章,请移步我的个人博客:

    Coolha:https://haxianhe.com/

  • 相关阅读:
    PHP:面向对象学习笔记,重点模拟Mixin(掺入)
    Mybatis Plus 更新
    Mybatis Plus 自定义SQL和分页插件
    Mybatis Plus 查询方法
    Mybatis Plus 快速入门
    Ribbon 负载均衡服务调用
    三个注册中心异同点
    Consul 服务注册与发现
    Spring Boot 集成 Swagger
    Eureka 服务注册与发现
  • 原文地址:https://www.cnblogs.com/haxianhe/p/11084610.html
Copyright © 2011-2022 走看看