当前位置:网站首页>mysql进阶(三十三)MySQL数据表添加字段
mysql进阶(三十三)MySQL数据表添加字段
2022-08-10 14:01:00 【InfoQ】
一、在末尾添加字段
ALTER TABLE <表名> ADD <新字段名><数据类型>[约束条件];
- <表名> 为数据表的名字;
- <新字段名> 为所要添加的字段的名字;
- <数据类型> 为所要添加的字段能存储数据的数据类型;
- [约束条件] 是可选的,用来对添加的字段进行约束。
USE test;
CREATE TABLE student (
id INT(4),
name VARCHAR(20),
sex CHAR(1));
ALTER TABLE
ALTER TABLE student ADD age INT(4);
DESC student;
二、在开头添加字段
ALTER TABLE <表名> ADD <新字段名> <数据类型> [约束条件] FIRST;
ALTER TABLE
ALTER TABLE student ADD stuId INT(4) FIRST;
DESC student;
三、在中间位置添加字段
ALTER TABLE <表名> ADD <新字段名> <数据类型> [约束条件] AFTER <已经存在的字段名>;
ALTER TABLE student ADD stuno INT(11) AFTER name;
DESC student;
边栏推荐
- Pointer (preliminary solution of C language)
- 3DS MAX batch export file script MAXScript with interface
- 【ECCV 2022|百万奖金】PSG大赛:追求“最全面”的场景理解
- 图式图例规范尺寸
- Vivado crashes or the message is not displayed
- Fragment的show和hide
- 【学习笔记】Redis的持久化
- Summary of Force Buckle Solution 640 - Solving Equations
- Do not access Object.prototype method ‘hasOwnProperty‘ from target object....
- 记录几道整型提升的题目
猜你喜欢
随机推荐
【剑指offer】---数组中的重复数字
2011年下半年 系统架构设计师 下午试卷 II
ABAP file operations involved in the Chinese character set of problems and solutions for trying to read
面试面到了一个腾讯30k出来的,有见识到何为精通MySQL调优
awk的简单使用
Error: Rule can only have one resource source (provided resource and test + include + exclude)
Lithium battery technology
A method that can make large data clustering 2000 times faster
Short read or OOM loading DB. Unrecoverable error, aborting now
系统的安全和应用(不会点安全的东西你怎么睡得着?)
写不完的数学试卷-----试卷生成器(Qt含源码)
Interface Automation Testing Basics
Makefile missing separator. Stop.怎么解决「建议收藏」
R语言实战应用案例:论文篇(一)-特殊柱形图绘制
开源SPL消灭数以万计的数据库中间表
List集合
In the second half of 2012 system architecture designers afternoon paper II
[target detection] small script: extract training set images and labels and update the index
[JS Advanced] Creating sub-objects and replacing this_10 in ES5 standard specification
需要被记录的OpenStack相关的命令_自己用