当前位置:网站首页>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';
边栏推荐
- Thymeleaf uses background custom tool classes to process text
- Photoshop plug-in action related concepts actionlist actiondescriptor actionlist action execution load call delete PS plug-in development
- Brief introduction of machine learning framework
- I spring and autumn blasting-1
- Go learning ----- relevant knowledge of JWT
- Mongdb learning notes
- Bugku easy_ nbt
- Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
- GPS original coordinates to Baidu map coordinates (pure C code)
- lv_font_conv离线转换
猜你喜欢

I spring web upload

NBA赛事直播超清画质背后:阿里云视频云「窄带高清2.0」技术深度解读

计算中间件 Apache Linkis参数解读

Fr exercise topic --- comprehensive question

Common MySQL interview questions

MongDB学习笔记

Talking about how dataset and dataloader call when loading data__ getitem__ () function

DVWA range clearance tutorial

lv_font_conv离线转换

SQL Server learning notes
随机推荐
Machine learning notes - gray wolf optimization
Aike AI frontier promotion (7.5)
How can the boss choose programmers to help me with development?
How to paste the contents copied by the computer into mobaxterm? How to copy and paste
P6183 [USACO10MAR] The Rock Game S
Ionic Cordova project modification plug-in
机器学习笔记 - 灰狼优化
Coding devsecops helps financial enterprises run out of digital acceleration
I want to inquire about how to ensure data consistency when a MySQL transaction updates multiple tables?
Calculate weight and comprehensive score by R entropy weight method
mapper.xml文件中的注释
Jmeter性能测试:ServerAgent资源监控
计算中间件 Apache Linkis参数解读
【jvm】运算指令
Creation and use of thymeleaf template
Photoshop plug-in action related concepts actionlist actiondescriptor actionlist action execution load call delete PS plug-in development
Mysql---- function
CPU design practice - Chapter 4 practical task 2 using blocking technology to solve conflicts caused by related problems
I spring and autumn blasting-1
What are the domestic formal futures company platforms in 2022? How about founder metaphase? Is it safe and reliable?