当前位置:网站首页>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
边栏推荐
- 【BIM+GIS】ArcGIS Pro2.8如何打开Revit模型,BIM和GIS融合?
- 229. 求众数 II
- Express中间件①(中间件的使用)
- Machine translation baseline
- [AI vision · quick review of NLP natural language processing papers today, issue 31] Fri, 15 APR 2022
- Express middleware ② (classification of Middleware)
- 指纹Key全国产化电子元件推荐方案
- 从MySQL数据库迁移到AWS DynamoDB
- MYSQL50道基础练习题
- Xiaomi, which has set the highest sales record of domestic mobile phones in overseas markets, paid renewed attention to the domestic market
猜你喜欢
![[echart] Introduction to echart](/img/40/e057f4ac07754fe6f3500f3dc72293.jpg)
[echart] Introduction to echart

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

【BIM+GIS】ArcGIS Pro2. 8 how to open Revit model, Bim and GIS integration?

使用大华设备开发行AI人流量统计出现时间不正确的原因分析

A function second kill 2sum 3sum 4sum problem

Xiaomi, which has set the highest sales record of domestic mobile phones in overseas markets, paid renewed attention to the domestic market

指纹Key全国产化电子元件推荐方案

Summary of knowledge map (3)

Opencv -- yoact case segmentation model reasoning

LabVIEW 小端序和大端序区别
随机推荐
Retrieval question answering system baseline
Go反射—Go语言圣经学习笔记
Express中间件②(中间件的分类)
TreeSet after class exercises
【论文阅读】【3d目标检测】point transformer
【BIM入门实战】Revit中的墙体层次以及常见问题解答
創下國產手機在海外市場銷量最高紀錄的小米,重新關注國內市場
【Echart】echart 入门
【时序】基于 TCN 的用于序列建模的通用卷积和循环网络的经验评估
Xiaomi, which has set the highest sales record of domestic mobile phones in overseas markets, paid renewed attention to the domestic market
UDP协议与TCP协议
Express middleware ① (use of Middleware)
Go反射法则
单极性非归零NRZ码、双极性非归零NRZ码、2ASK、2FSK、2PSK、2DPSK及MATLAB仿真
php导出Excel表格
Hard core chip removal
现货黄金操作技巧_估波曲线
[BIM introduction practice] wall hierarchy and FAQ in Revit
A new method for evaluating the quality of metagenome assembly - magista
Basic introduction to spot gold