当前位置:网站首页>SQL statement for adding columns in MySQL table
SQL statement for adding columns in MySQL table
2022-04-23 04:31:00 【The hunter is eating meat】
Here is Mysql Add column SQL grammar .
1、 Add column
1.1、 Add a row :
Add a column to an already built table :
alter table TABLE_NAME add column NEW_COLUMN_NAME varchar(20) not null ;
1.2、 Specify the insertion position :
By default , The inserted column is at the end of the table , If you want to specify where to insert the column , as follows :
alter table TABLE_NAME add column NEW_COLUMN_NAME varchar(20) not null after COLUMN_NAME ;
1.3、 Insert into 1 Column :
Above is inserted after a column , If you want to insert into the 1 Column , as follows :
alter table TABLE_NAME add column NEW_COLUMN_NAME varchar(20) not null first ;
2、 Example
Want to insert several identical fields into each table , such as Creation time
、 Update time
、 remarks
, Its type and length are as follows :
CREATE TABLE `contact` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT ' Primary key ',
`platform_id` varchar(50) DEFAULT NULL COMMENT ' platform ID',
`code` varchar(10) DEFAULT NULL COMMENT ' Response identification .00 It means success ',
`swift_number` varchar(50) DEFAULT NULL COMMENT ' Serial number ',
`create_time` datetime DEFAULT NULL COMMENT ' Creation time ',
`update_time` datetime DEFAULT NULL COMMENT ' Update time ',
`remark` varchar(100) DEFAULT NULL COMMENT ' remarks ',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
The operation is as follows :
1) Copy above contact
In the sentence Creation time
、 Update time
、 remarks
Of Three elements , And add SQL sentence alter table TABLE_NAME add column
, complete SQL The statement is as follows :
alter table TABLE_NAME add column `create_time` datetime DEFAULT NULL COMMENT ' Creation time ' ;
alter table TABLE_NAME add column `update_time` datetime DEFAULT NULL COMMENT ' Update time ' ;
alter table TABLE_NAME add column `remark` varchar(100) DEFAULT NULL COMMENT ' remarks ' ;
2) TABLE_NAME Modify to all table names .
alter table tb_user add column `create_time` datetime DEFAULT NULL COMMENT ' Creation time ' ;
alter table tb_user add column `update_time` datetime DEFAULT NULL COMMENT ' Update time ' ;
alter table tb_user add column `remark` varchar(100) DEFAULT NULL COMMENT ' remarks ' ;
版权声明
本文为[The hunter is eating meat]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230417436395.html
边栏推荐
- MATLAB lit plusieurs diagrammes fig et les combine en un seul diagramme (sous forme de sous - Diagramme)
- Basic introduction to spot gold
- 【BIM入门实战】Revit建筑墙体:构造、包络、叠层图文详解
- MYSQL50道基础练习题
- Matlab reads multiple fig graphs and then combines them into one graph (in the form of sub graph)
- 2019 is coming to an end, the longest day.
- Matlab minimalist configuration of vscode configuration
- The latest price trend chart and trading points of London Silver
- [AI vision · quick review of robot papers today, issue 31] Fri, 15 APR 2022
- 【BIM+GIS】ArcGIS Pro2. 8 how to open Revit model, Bim and GIS integration?
猜你喜欢
Difference between LabVIEW small end sequence and large end sequence
/etc/bash_completion.d目录作用(用户登录立刻执行该目录下脚本)
第四章 --- 了解标准设备文件、过滤器和管道
QtSpim手册-中文翻译
Why recommend you to study embedded
洛谷P1858 【多人背包】 (背包求前k优解)
C语言常用字符串处理函数
Use recyclerview to realize left-right side-by-side classification selection
Chlamydia infection -- causes, symptoms, treatment and Prevention
[mapping program design] coordinate inverse artifact v1 0 (with C / C / VB source program)
随机推荐
Set经典小题目
Matlab minimalist configuration of vscode configuration
As a code farmer, what kind of experience is it that a girlfriend can code better than herself?
QT program integration easyplayer RTSP streaming media player screen flicker what is the reason?
A function second kill 2sum 3sum 4sum problem
MYSQL查询至少连续n天登录的用户
【BIM+GIS】ArcGIS Pro2. 8 how to open Revit model, Bim and GIS integration?
MYSQL50道基础练习题
【Pytorch基础】torch.split()用法
MYSQL去重方法汇总
Effects of antibiotics on microbiome and human health
国外LEAD,联盟经理常见问答
KVM error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock‘
AWS EKS添加集群用户或IAM角色
单片机串口数据处理(2)——uCOSIII+循环队列接收数据
Microbial neuroimmune axis -- the hope of prevention and treatment of cardiovascular diseases
229. 求众数 II
无线充电全国产化电子元件推荐方案
[Li Hongyi 2022 machine learning spring] hw6_ Gan (don't understand...)
在AWS控制台创建VPC(无图版)