当前位置:网站首页>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';
边栏推荐
- Hongmeng system -- Analysis from the perspective of business
- Want to ask the big guy, is there any synchronization from Tencent cloud Mysql to other places? Binlog saved by Tencent cloud MySQL on cos
- Huiyuan, 30, is going to have a new owner
- Photoshop plug-in - action related concepts - actions in non loaded execution action files - PS plug-in development
- Talk about your understanding of microservices (PHP interview theory question)
- mapper. Comments in XML files
- Number protection AXB function! (essence)
- 超越PaLM!北大硕士提出DiVeRSe,全面刷新NLP推理排行榜
- Array sorting num ranking merge in ascending order
- JS bright blind your eyes date selector
猜你喜欢
lv_font_conv离线转换
Selection and use of bceloss, crossentropyloss, sigmoid, etc. in pytorch classification
Huiyuan, 30, is going to have a new owner
Au - delà du PARM! La maîtrise de l'Université de Pékin propose diverse pour actualiser complètement le classement du raisonnement du NLP
美团优选管理层变动:老将刘薇调岗,前阿里高管加盟
亿咖通科技通过ISO27001与ISO21434安全管理体系认证
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
OSI 七层模型
CODING DevSecOps 助力金融企业跑出数字加速度
P1451 求细胞数量/1329:【例8.2】细胞
随机推荐
社区团购撤城“后遗症”
Bugku's Ping
Bugku's Ah Da
Bugku cyberpunk
Cartoon: what are the attributes of a good programmer?
Bugku's eyes are not real
The difference between SQL Server char nchar varchar and nvarchar
亿咖通科技通过ISO27001与ISO21434安全管理体系认证
P6183 [USACO10MAR] The Rock Game S
Calculate weight and comprehensive score by R entropy weight method
Crud de MySQL
Misc Basic test method and knowledge points of CTF
Bugku's Eval
The difference between abstract classes and interfaces in PHP (PHP interview theory question)
【jvm】运算指令
Go learning ----- relevant knowledge of JWT
easyOCR 字符识别
Type declaration of all DOM elements in TS
How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
Machine learning notes - gray wolf optimization