当前位置:网站首页>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
边栏推荐
- Xiaohongshu was exposed to layoffs of 20% as a whole, and the internal volume among large factories was also very serious
- TreeSet课后练习
- [AI vision · quick review of robot papers today, issue 32] wed, 20 APR 2022
- Redis 命令大全
- Bacterial infection and antibiotic use
- 阿里云IoT流转到postgresql数据库方案
- 【BIM+GIS】ArcGIS Pro2. 8 how to open Revit model, Bim and GIS integration?
- 【测绘程序设计】坐标方位角推算神器(C#版)
- QT program integration easyplayer RTSP streaming media player screen flicker what is the reason?
- 兼容NSR20F30NXT5G的小体积肖特基二极管
猜你喜欢

针对NFT的网络钓鱼

Set classic topics
![[AI vision · quick review of robot papers today, issue 32] wed, 20 APR 2022](/img/eb/916a3fc1a89356fd8e74b943172ac3.png)
[AI vision · quick review of robot papers today, issue 32] wed, 20 APR 2022

matlab讀取多張fig圖然後合並為一張圖(子圖的形式)

Matlab reads multiple fig graphs and then combines them into one graph (in the form of sub graph)

【BIM+GIS】ArcGIS Pro2.8如何打开Revit模型,BIM和GIS融合?

Bacterial infection and antibiotic use

上海航芯技术分享 | ACM32 MCU安全特性概述

The perfect combination of collaborative process and multi process

Why recommend you to study embedded
随机推荐
协程与多进程的完美结合
LabVIEW 小端序和大端序区别
【BIM入门实战】Revit中的墙体层次以及常见问题解答
Iron and intestinal flora
php导出Excel表格
【BIM+GIS】ArcGIS Pro2. 8 how to open Revit model, Bim and GIS integration?
QtSpim手册-中文翻译
Opencv -- yoact case segmentation model reasoning
Who will answer the question?
[BIM introduction practice] wall hierarchy and FAQ in Revit
VHDL implementation of 32-bit binary to BCD code
MYSQL去重方法汇总
TreeSet after class exercises
Stm32f4 MCU ADC sampling and FFT of ARM-DSP Library
【ICCV 2019】MAP-VAE:Multi-Angle Point Cloud-VAE: Unsupervised Feature Learning for 3D Point Clouds..
IEEE Transactions on Systems, Man, and Cybernetics: Systems(TSMC)投稿须知
记录一下盲注脚本
【Echart】echart 入門
Redis 命令大全
【测绘程序设计】坐标反算神器V1.0(附C/C#/VB源程序)