10人参与 • 2025-07-25 • Mysql
数据表由行和列组成,专业术语中:
mysql支持三种字段添加位置,语法格式均通过alter table指令实现:
alter table 表名 add 新字段名 数据类型;
操作示例:
create table student ( id int(4), name varchar(20), sex char(1) );
alter table student add age int(4);
| field | type | null | key | |-------|-------------|------|-----| | id | int(4) | yes | | | name | varchar(20) | yes | | | sex | char(1) | yes | | | age | int(4) | yes | |
alter table 表名 add 新字段名 数据类型 first;
操作示例:
alter table student add stuid int(4) first;
结构验证:
| stuid | int(4) | yes | | | id | int(4) | yes | |
alter table 表名 add 新字段名 数据类型 after 目标字段;
操作示例:
alter table student add stuno int(11) after name;
结构验证:
| name | varchar(20) | yes | | | stuno | int(11) | yes | |
-- 在jobintenation_info_flag后面添加这三个字段 alter table t_resume add column resume_product_flag tinyint(1) not null default 0 comment '简历作品记录,0:未完成,1:完成' after jobintenation_info_flag, add self_introduce_flag tinyint(1) not null default 0 comment '自我简介记录,0:未完成,1:完成' after jobintenation_info_flag, add language_ability_flag tinyint(1) not null default 0 comment '语言能力记录,0:未完成,1:完成' after jobintenation_info_flag alter table t_resume drop column language_ability_flag; alter table t_resume drop column self_introduce_flag; alter table t_resume drop column resume_product_flag;
到此这篇关于mysql数据表添加字段的三种方式总结的文章就介绍到这了,更多相关mysql数据表添加字段内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论