当前位置:网站首页>mysql table 中增加列的SQL语句
mysql table 中增加列的SQL语句
2022-04-23 04:18:00 【猎人在吃肉】
下面是 Mysql 的增加列的 SQL语法。
1、增加列
1.1、增加一列:
在一个已经建好的表中增加一列:
alter table TABLE_NAME add column NEW_COLUMN_NAME varchar(20) not null ;
1.2、指定插入位置:
默认情况下,插入的列是在表的最后面, 如果想指定插入列的位置,如下:
alter table TABLE_NAME add column NEW_COLUMN_NAME varchar(20) not null after COLUMN_NAME ;
1.3、插入到第1列:
上面是插入到某列的后面,如果想插入到第1列,如下:
alter table TABLE_NAME add column NEW_COLUMN_NAME varchar(20) not null first ;
2、示例
想在每个表中都插入几个相同的字段,比如 创建时间
、更新时间
、备注
,其类型和长度如下:
CREATE TABLE `contact` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`platform_id` varchar(50) DEFAULT NULL COMMENT '平台ID',
`code` varchar(10) DEFAULT NULL COMMENT '响应标识.00表示成功',
`swift_number` varchar(50) DEFAULT NULL COMMENT '流水号',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`remark` varchar(100) DEFAULT NULL COMMENT '备注',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
操作如下:
1)复制 上面 contact
语句中创建时间
、更新时间
、备注
的 三行,并在前面添加 SQL语句 alter table TABLE_NAME add column
,完整 SQL语句如下:
alter table TABLE_NAME add column `create_time` datetime DEFAULT NULL COMMENT '创建时间' ;
alter table TABLE_NAME add column `update_time` datetime DEFAULT NULL COMMENT '更新时间' ;
alter table TABLE_NAME add column `remark` varchar(100) DEFAULT NULL COMMENT '备注' ;
2) TABLE_NAME 修改为所有的表名。
alter table tb_user add column `create_time` datetime DEFAULT NULL COMMENT '创建时间' ;
alter table tb_user add column `update_time` datetime DEFAULT NULL COMMENT '更新时间' ;
alter table tb_user add column `remark` varchar(100) DEFAULT NULL COMMENT '备注' ;
版权声明
本文为[猎人在吃肉]所创,转载请带上原文链接,感谢
https://xiaojin21cen.blog.csdn.net/article/details/118360662
边栏推荐
猜你喜欢
上海航芯技术分享 | ACM32 MCU安全特性概述
Express middleware ② (classification of Middleware)
阿里云IoT流转到postgresql数据库方案
Chlamydia infection -- causes, symptoms, treatment and Prevention
Summary of knowledge map (3)
Bacterial infection and antibiotic use
【BIM+GIS】ArcGIS Pro2. 8 how to open Revit model, Bim and GIS integration?
[echart] démarrer avec echart
Qt程序集成EasyPlayer-RTSP流媒体播放器出现画面闪烁是什么原因?
洛谷P1858 【多人背包】 (背包求前k优解)
随机推荐
现货黄金操作技巧_估波曲线
TreeSet after class exercises
CRF based medical entity recognition baseline
Express middleware ② (classification of Middleware)
Alibaba cloud IOT transfer to PostgreSQL database scheme
[AI vision · quick review of robot papers today, issue 30] Thu, 14 APR 2022
用D435i录制自己的数据集运行ORBslam2并构建稠密点云
Machine translation baseline
[mathematical modeling] my mathematical memory
UDP protocol and TCP protocol
TreeSet课后练习
Overview of knowledge map (II)
STM32单片机ADC规则组多通道转换-DMA模式
【李宏毅2022 机器学习春】hw6_GAN(不懂..)
中国移动日赚2.85亿很高?其实是5G难带来更多利润,那么钱去哪里了?
VSCode配置之Matlab极简配置
Shopping mall for transportation tools based on PHP
Summary of knowledge map (3)
【论文阅读】【3d目标检测】Voxel Transformer for 3D Object Detection
C language character constant