当前位置:网站首页>MySQL表字段调整
MySQL表字段调整
2022-07-05 15:00:00 【一把青龙湾月刀】
新增字段格式:
ALTER TABLE 表名 ADD 字段名称 字段类型(字段长短-选填) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL(是否不可为空) DEFAULT 0(默认值) COMMENT '备注' AFTER 在指定字段之后(不加默认最后);
新增例子:
ALTER TABLE table_name ADD COLUMN age varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 0 COMMENT '年龄' AFTER name;
修改字段格式:
ALTER TABLE table_name MODIFY COLUMN 字段名 新数据类型 新类型长度 新默认值 新注释;
-- COLUMN关键字可以省略不写
修改字段例子:
ALTER TABLE table_name MODIFY COLUMN 'column' decimal (15,2) DEFAULT NULL COMMENT '注释'; -- 正常,能修改字段类型、类型长度、默认值、注释
修改字段类型为无符号:
ALTER TABLE table_name MODIFY COLUMN 'column' BIGINT(11) UNSIGNED DEFAULT '0' COMMENT '注释';
ALTER TABLE 表名 CHANGE [column] 旧字段名 新字段名 新数据类型;
alter table table_name change old_column new_column varchar(100) DEFAULT '1.2' COMMENT '注释'; -- 正常,此时字段名称没有改变,能修改字段类型、类型长度、默认值、注释
修改表默认值 若存在默认值先删除后修改
alter table table_name alter column column drop default;
alter table table_name alter column column set default '0';
边栏推荐
- Common MySQL interview questions (1) (written MySQL interview questions)
- qt creater断点调试程序详解
- 亿咖通科技通过ISO27001与ISO21434安全管理体系认证
- CPU design related notes
- Does maxcompute have SQL that can query the current storage capacity (KB) of the table?
- 机器学习框架简述
- Long list optimized virtual scrolling
- Super wow fast row, you are worth learning!
- lvgl 显示图片示例
- Bugku easy_ nbt
猜你喜欢
随机推荐
Bugku's Ah Da
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
Go learning ----- relevant knowledge of JWT
Calculate weight and comprehensive score by R entropy weight method
Garbage collection mechanism of PHP (theoretical questions of PHP interview)
Photoshop插件-动作相关概念-非加载执行动作文件中动作-PS插件开发
mapper.xml文件中的注释
Reasons and solutions for redis cache penetration and cache avalanche
CPU design practice - Chapter 4 practical task 2 using blocking technology to solve conflicts caused by related problems
Bugku's Ping
Interpretation of Apache linkage parameters in computing middleware
可转债打新在哪里操作开户是更安全可靠的呢
华为哈勃化身硬科技IPO收割机
GPS原始坐标转百度地图坐标(纯C代码)
Bugku alert
Install and configure Jenkins
No one consults when doing research and does not communicate with students. UNC assistant professor has a two-year history of teaching struggle
I want to inquire about how to ensure data consistency when a MySQL transaction updates multiple tables?
Machine learning notes - gray wolf optimization
Aike AI frontier promotion (7.5)