MySQL-ALTER TABLE命令学习[20180503]
学习ALTER TABLE删除、添加和修改字段和类型
mysql> alter table alter_tab01 drop col01;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table alter_tab01 add col01 char(20);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> alter table alter_tab01 add col02 char(20) first;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> alter table alter_tab01 add col03 char(20) after id;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> alter table alter_tab01 add col04 char(20) not null;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) mysql> show columns from alter_tab01;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| col02 | char(20) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| col03 | char(20) | YES | | NULL | |
| col01 | char(20) | YES | | NULL | |
| col04 | char(20) | NO | | NULL | |
+-------+----------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> alter table alter_tab01 modify col02 varchar(10);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> alter table alter_tab01 change col02 new_col02 char(2);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> show columns from alter_tab01;
+-----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+-------+
| new_col02 | char(2) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
| col03 | char(20) | YES | | NULL | |
| col01 | char(20) | YES | | NULL | |
| col04 | char(20) | NO | | NULL | |
+-----------+----------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> alter table alter_tab01 modify id bigint not null default 1;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> show columns from alter_tab01;
+-----------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------+------+-----+---------+-------+
| new_col02 | char(2) | YES | | NULL | |
| id | bigint(20) | NO | | 1 | |
| col03 | char(20) | YES | | NULL | |
| col01 | char(20) | YES | | NULL | |
| col04 | char(20) | NO | | NULL | |
+-----------+------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> alter table alter_tab01 alter new_col02 set default '01';
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> show columns from alter_tab01;
+-----------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------+------+-----+---------+-------+
| new_col02 | char(2) | YES | | 01 | |
| id | bigint(20) | NO | | 1 | |
| col03 | char(20) | YES | | NULL | |
| col01 | char(20) | YES | | NULL | |
| col04 | char(20) | NO | | NULL | |
+-----------+------------+------+-----+---------+-------+
5 rows in set (0.00 sec) mysql> alter table alter_tab01 alter new_col02 drop default;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> show columns from alter_tab01;
+-----------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------+------+-----+---------+-------+
| new_col02 | char(2) | YES | | NULL | |
| id | bigint(20) | NO | | 1 | |
| col03 | char(20) | YES | | NULL | |
| col01 | char(20) | YES | | NULL | |
| col04 | char(20) | NO | | NULL | |
+-----------+------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> show table status like 'alter_tab01'\G
*************************** 1. row ***************************
Name: alter_tab01
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 0
Avg_row_length: 0
Data_length: 16384
Max_data_length: 0
Index_length: 0
Data_free: 4194304
Auto_increment: NULL
Create_time: 2018-05-03 16:11:39
Update_time: NULL
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec) mysql> alter table alter_tab01 engine=MyISAM;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0 mysql> show table status like 'alter_tab01'\G
*************************** 1. row ***************************
Name: alter_tab01
Engine: MyISAM
Version: 10
Row_format: Fixed
Rows: 0
Avg_row_length: 0
Data_length: 0
Max_data_length: 54887620458577919
Index_length: 1024
Data_free: 0
Auto_increment: NULL
Create_time: 2018-05-03 16:12:35
Update_time: 2018-05-03 16:12:35
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
mysql> alter table alter_tab01 rename to alter_tab02;
Query OK, 0 rows affected (0.00 sec) mysql> show table status like 'alter_tab02'\G
*************************** 1. row ***************************
Name: alter_tab02
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 0
Avg_row_length: 0
Data_length: 16384
Max_data_length: 0
Index_length: 0
Data_free: 4194304
Auto_increment: NULL
Create_time: 2018-05-03 16:14:02
Update_time: NULL
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
MySQL-ALTER TABLE命令学习[20180503]的更多相关文章
- SQL ALTER TABLE 命令
SQL ALTER TABLE 命令 SQL ALTER TABLE 命令用于添加.删除或者更改现有数据表中的列. 你还可以用 ALTER TABLE 命令来添加或者删除现有数据表上的约束. 语法: ...
- MySQL ALTER TABLE: ALTER vs CHANGE vs MODIFY COLUMN
ALTER COLUMN 语法: ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT} 作用: 设置或删除列的默认值.该操作会直接修 ...
- mysql ALTER TABLE语句 语法
mysql ALTER TABLE语句 语法 作用:用于在已有的表中添加.修改或删除列.无铁芯直线电机 语法:添加列:ALTER TABLE table_name ADD column_name da ...
- 【待整理】MySQL alter table modify vs alter table add产生state不一样
MySQL:5.6.35 OS:redhat5.8 今天更新数据库某些表字段,有如下两SQL: ①alter table xx modify xxxx;(表大概是77w) ②alter table s ...
- mysql Alter table设置default的问题,是bug么?
不用不知道,用了没用? 昨天在线上创建了一个表,其中有两个列是timestamp类型的,创建语句假设是这样的: create table timetest(id int, createtime tim ...
- mysql truncate table命令使用总结
truncate使用注意 由于上过truncate table a_table命令一次当,将教训记录下来,以示警戒! mysql truncate table a_table命令受影响结果说明 ...
- MySQL ALTER TABLE语法
先看一下定义(密密麻麻) ALTER TABLE tbl_name [alter_specification [, alter_specification] ...] [partition_optio ...
- MySQL alter table时执行innobackupex全备再看Seconds_Behind_Master
1.场景描述 早上7:25 接到Report中心同学告警,昨天业务报表数据没有完整跑出来,缺少500位业务员的数据,并且很快定位到,缺少的是huabei_order库上的数据.Report中心的数据是 ...
- mysql alter table
准备: create table t(x int,y int); 用法 1: 修改列的数据类 alter table t modify column y nvarchar(32); 用法2: 给表加一 ...
随机推荐
- Android使用ToolBar+DrawerLayout+NavigationView实现侧滑抽屉效果
学会使用DrawerLayout 学会使用NavigationView 学会使用ToolBar+DrawerLayout+NavigationView实现侧滑抽屉效果 学会实现Toolbar在顶部以及 ...
- lodop 二维码内容多少
QRCode最多能放181个汉字:LODOP.ADD_PRINT_BARCODE(248,6,60,60,"QRCode","一二三四五六七八九十二二三四五六七八九十三二 ...
- IIS 中托管基于TCP绑定的WCF服务
IIS 中托管基于TCP绑定的WCF服务 一.创建一个基于TCP绑定的WCF服务 1.创建一个的简单的服务具体代码如下 服务契约定义 namespace SimpleService { // 注意: ...
- leetCode题解之删除单链表中指定的元素
1.问题描述 Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> ...
- Fuckey V1.0 Beta版发布!!!
Fuckey,以前叫FullNexus4,只因为当时想做一个软件给自己的Nexus 4,方便方便一下,不过这名字感觉太局限了,毕竟很多朋友不是使用的Nexus 4的手机,但却还是使用了FullNexu ...
- ARC下block使用情况
ARC与MRC的block有着一些区别,笔记整理ARC的block,仅仅是自己参考的笔记,详情请参考 http://www.cnbluebox.com/?p=255 在开始之前,请新建一个Model类 ...
- 点击单个cell高度变化的动画效果
点击单个cell高度变化的动画效果 效果 说明 1. 点击单个cell的时候,其展开与缩放动画实现起来是很麻烦的,做过相关需求的朋友一定知道其中的坑 2. 本例子只是提供了一个解决方案,为了简化操作, ...
- [UI] 精美UI界面欣赏[11]
精美UI界面欣赏[11]
- [转] iOS文字排版(CoreText)那些事儿
文章转载自 http://www.cocoachina.com/applenews/devnews/2014/0521/8504.html iOS文字排版(CoreText)那些事儿 转自阿毛的蛋疼地 ...
- RESTful 架构基础
源自:https://mp.weixin.qq.com/s/wEr2jAVphzB1G_MISlLU0w REST(Representational State Transfer)架构风格是一种世界观 ...