• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
星之寒
博客园    首页    新随笔    联系   管理    订阅  订阅
mysql数据结构操作

删除列

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;

posted on 2019-12-17 11:21  星之寒  阅读(334)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3