加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

修改MySQL字段类型

发布时间:2023-10-25 15:10:48 所属栏目:MySql教程 来源:
导读:在MySQL中,alter table语句是用于在已有的表中添加、修改或删除列(字段)的。

1、添加字段(列)

alter table 表名 add 字段名 数据类型

复制代码

示例:在表 "Persons" 中添加一个名为 "Birthday
在MySQL中,alter table语句是用于在已有的表中添加、修改或删除列(字段)的。
 
1、添加字段(列)
 
alter table 表名 add 字段名 数据类型
 
复制代码
 
示例:在表 "Persons" 中添加一个名为 "Birthday" 的新列,数据类型为“date”
 
alter table Persons add Birthday date
 
复制代码
 
说明:新列 "Birthday" 的类型是 date,可以存放日期
 
2、修改字段名
 
alter table 表名 rename column A to B
 
复制代码
 
3、修改字段类型
 
alter table 表名 alter column 字段名 数据类型
 
复制代码
 
示例:将表 "Persons" 中的 "Birthday" 列的数据类型改为“year”
 
alter table Persons alter column Birthday year
 
复制代码
 
说明:"Birthday" 列的数据类型是 year,可以存放 2 位或 4 位格式的年份。
 
4、删除字段
 
alter table 表名 drop column 字段名
 
复制代码
 
示例:删除 "Person" 表中的 "Birthday" 列
 
alter table Persons drop column Birthday
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章