mysql修改_mysql修改表操作

一: 修改表信息

1.修改表名

alter table test_a rename to sys_app;

2.修改表注释

alter table sys_application comment '系统信息表';

二:修改字段信息

1.修改字段类型和注释

alter table sys_application modify column app_name varchar(20) COMMENT '应用的名称';

2.修改字段类型

alter table sys_application modify column app_name text;

3.设置字段允许为空

alter table sys_application modify column description varchar(255) null COMMENT '应用描述';

4.增加一个字段,设好数据类型,且不为空,添加注释

alert table sys_application add `url` varchar(255) not null comment '应用访问地址';

5.增加主键

alter table t_app add aid int(5) not null ,add primary key (aid);

6.增加自增主键

alter table t_app add aid int(5) not null auto_increment ,add primary key (aid);

7.修改为自增主键

alter table t_app modify column aid int(5) auto_increment ;

8.修改字段名字(要重新指定该字段的类型)

alter table t_app change name app_name varchar(20) not null;

9.删除字段

alter table t_app drop aid;

10.在某个字段后增加字段

alter table `t_app` add column gateway_id int not null default 0 AFTER `aid`; #(在哪个字段后面添加)

11.调整字段顺序

alter table t_app change gateway_id gateway_id int not null after aid ; #(注意gateway_id出现了2次)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值