#新增一个字段
alter table 表名 add COLUMN 字段名 类型长度 DEFAULT NULL COMMENT '注释内容';
#例如:
alter table device_log_run_operation add COLUMN parser_status VARCHAR(4) DEFAULT NULL COMMENT '解析文件状态,0:解析成功;1:解析失败;';
#批量新增字段,方法一
#事务开始
begin;
alter table device_log_run_operation add COLUMN title VARCHAR(500) DEFAULT NULL COMMENT '日志标题';
alter table device_log_run_operation add COLUMN remote_addr VARCHAR(255) NOT NULL COMMENT '操作ip地址';
commit;
#批量新增字段,提交事务,事务结束
#批量新增字段,方法二
alter table 表名 add (字段名1 类型(长度),字段名2 类型(长度),字段名3 类型(长度));
#例如:
alter table device_log_run_operation
add (
status int(11) DEFAULT NULL COMMENT '状态:0-成功;1-失败',
remote_addrss VARCHAR(255) NOT NULL COMMENT '操作的ip地址',
insert_times datetime DEFAULT NULL COMMENT '创建时间'
);
#为表添加注释
ALTER TABLE 表名 COMMENT'表注释内容';
ALTER TABLE device_files_info COMMENT'设备运行文件';
#修改字段的长度/新增注释
alter table 表名 modify column 字段名 类型长度 COMMENT '字段注释内容';
#例如:
alter table device_log_run_operation modify column title varchar(500) COMMENT '标题';
#批量修改字段名称
alter table 表名
change 修改前字段名 修改后字段名称 int(11) not null,
change 修改前字段名 修改后字段名称 int(11) not null
#例如:
alter table device_log_run_operation
change remote_addrss opeartor_ip VARCHAR(255) DEFAULT NULL COMMENT '操作的ip地址',
change insert_time create_time datetime DEFAULT NULL COMMENT '创建时间'
#删除一个字段
alter table 表名 DROP COLUMN 字段名;
alter table device_log_run_operation DROP COLUMN status ;