当前位置:网站首页>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
边栏推荐
- Gut liver axis: host microbiota interaction affects hepatocarcinogenesis
- zynq平台交叉编译器的安装
- Stm32f4 MCU ADC sampling and FFT of ARM-DSP Library
- Common string processing functions in C language
- Nel ASA: her ø Ya facility in Norway officially opened
- 阿里云IoT流转到postgresql数据库方案
- 协程与多进程的完美结合
- [echart] démarrer avec echart
- Xiaohongshu was exposed to layoffs of 20% as a whole, and the internal volume among large factories was also very serious
- Go反射法则
猜你喜欢

MYSQL查询至少连续n天登录的用户

Fusobacterium -- symbiotic bacteria, opportunistic bacteria, oncobacterium

Express middleware ② (classification of Middleware)

Use recyclerview to realize left-right side-by-side classification selection

QtSpim手册-中文翻译

HMS Core Discovery第14期回顾长文|纵享丝滑剪辑,释放视频创作力

STM32单片机ADC规则组多通道转换-DMA模式

The whole process of connecting the newly created unbutu system virtual machine with xshell and xftp

383. 赎金信

Second kill all interval related problems
随机推荐
Chapter 4 - understanding standard equipment documents, filters and pipelines
[BIM introduction practice] Revit building wall: detailed picture and text explanation of structure, envelope and lamination
C语言 字符常量
[mapping program design] coordinate inverse artifact v1 0 (with C / C / VB source program)
Basic introduction to spot gold
Understand the gut organ axis, good gut and good health
[Li Hongyi 2022 machine learning spring] hw6_ Gan (don't understand...)
C语言常用字符串处理函数
QtSpim手册-中文翻译
MYSQL去重方法汇总
单极性非归零NRZ码、双极性非归零NRZ码、2ASK、2FSK、2PSK、2DPSK及MATLAB仿真
MATLAB lit plusieurs diagrammes fig et les combine en un seul diagramme (sous forme de sous - Diagramme)
从MySQL数据库迁移到AWS DynamoDB
thymeleaf th:value 为null时报错问题
補:注解(Annotation)
eksctl 部署AWS EKS
Difference between LabVIEW small end sequence and large end sequence
Express middleware ② (classification of Middleware)
[AI vision · quick review of today's sound acoustic papers, issue 2] Fri, 15 APR 2022
TreeSet课后练习