当前位置:网站首页>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
边栏推荐
- 2019 is coming to an end, the longest day.
- STM32单片机ADC规则组多通道转换-DMA模式
- Opencv -- yoact case segmentation model reasoning
- 指纹Key全国产化电子元件推荐方案
- Hard core chip removal
- Leetcode->1 两数之和
- IDE Idea 自动编译 与 On Upate Action 、 On Frame Deactivation 的配置
- 记录一下盲注脚本
- Common string processing functions in C language
- What is software acceptance testing? What are the benefits of acceptance testing conducted by third-party software testing institutions?
猜你喜欢
Network principle | connection management mechanism in TCP / IP important protocol and core mechanism
STM32F4单片机ADC采样及ARM-DSP库的FFT
【BIM入门实战】Revit建筑墙体:构造、包络、叠层图文详解
Single chip microcomputer serial port data processing (2) -- ucosiii + cyclic queue receiving data
【论文阅读】【3d目标检测】point transformer
補:注解(Annotation)
Opencv -- yoact case segmentation model reasoning
LabVIEW 小端序和大端序区别
383. 赎金信
Express middleware ② (classification of Middleware)
随机推荐
Xiaohongshu was exposed to layoffs of 20% as a whole, and the internal volume among large factories was also very serious
2020 is coming to an end, special and unforgettable.
Who will answer the question?
[mapping program design] coordinate azimuth calculation artifact (version C)
Cause analysis of incorrect time of AI traffic statistics of Dahua Equipment Development Bank
520.检测大写字母
PHP export excel table
mysql table 中增加列的SQL语句
【测绘程序设计】坐标方位角推算神器(C#版)
Effects of antibiotics on microbiome and human health
QT program integration easyplayer RTSP streaming media player screen flicker what is the reason?
Qtspim manual - Chinese Translation
STM32 upper μ C / shell transplantation and Application
那些年我面试过的Android开发岗总结(附面试题+答案解析)
兼容NSR20F30NXT5G的小体积肖特基二极管
Go 语言中的 logger 和 zap 日志库
Brushless motor drive scheme based on Infineon MCU GTM module
智能电子秤全国产化电子元件推荐方案
阿里云IoT流转到postgresql数据库方案
Interaction of diet gut microbiota on cardiovascular disease