zoukankan      html  css  js  c++  java
  • mysql 常见ALTER TABLE操作

    删除列

    alter table table-name drop col-name;

    增加列(单列)

    alter table table-name add col-name col-type comment 'xxx';

    增加列(多列)

    alter table table-name add col-name col-type comment 'xxx', add col-name col-type(col-length) comment 'xxx';

    增加表字段并指明字段放置为第一列

    alter table table-name add col-name col-type COMMENT 'sss' FIRST;

    增加表字段并指明字段放置为特定列后面

    alter table table-name add col-name col-type after col-name-1;

    使用MODIFY修改字段类型

    alter table table-name modify column col-name col-type;

    使用CHANGE修改字段类型

    alter table table-name change col-name col-name col-type;

    使用CHANGE修改字段名称

    alter table table-name change old-col-name new-col-name col-type;

    修改列类型、长度

    alter table table-name change old-col-name new-col-name new-col-type;

    查看表中列属性

    show columns from table-name;

    修改表名

    rename table old-table-name to new-table-name;

    为字段设置NULL和DEFAULT

    alter table table-name modify col-name col-type not null default 100;

    修改字段的默认值

    alter table table-name alter col-name set default 10000;

    字段删除默认值 

    alter table table-name alter col-name drop default;

    新增到指定位置语法
    alter table app add `name` varchar(64) DEFAULT '' COMMENT '应用名称' after `app_id`;
    修改顺序语法:alter table 表名 change 老字段名 新字段名 字段各种约束 after 字段;
    alter table `app` change `title` `title` VARCHAR(64) DEFAULT '' COMMENT '名称' after `name`;

  • 相关阅读:
    【软件测试】软件缺陷粗浅认识及白盒测试举例
    【软件测试】等价类划分
    【软件测试】对本门课程粗浅理解
    阿里云服务器本地ping超时,远程可以正常ping通
    不忘初心
    开源框架、控件、组件、插件记录
    Flex中窗口可随意拖拽功能实现
    初探数据类型相关问题
    [TSCTF-J 2021] 解题报告
    指针
  • 原文地址:https://www.cnblogs.com/lwcode6/p/11326666.html
Copyright © 2011-2022 走看看