5.6中,发现其实alter column 和更改modify column 步骤是一样的

mysql> create table xs(name varchar(12),age int default 5);
Query OK, 0 rows affected (0.34 sec)

mysql> insert into xs values('a',4);
Query OK, 1 row affected (0.05 sec)

mysql> set profiling=1;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> alter table xs modify age int not null default 3;

Query OK, 0 rows affected (0.38 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> show profiles;
+----------+------------+--------------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+--------------------------------------------------+
| 1 | 0.38208725 | alter table xs modify age int not null default 3 |
+----------+------------+--------------------------------------------------+
4 rows in set, 1 warning (0.00 sec)

mysql> show profile for query 1;
+--------------------------------+----------+
| Status | Duration |
+--------------------------------+----------+
| starting | 0.000114 |
| checking permissions | 0.000007 |
| checking permissions | 0.000026 |
| init | 0.000006 |
| Opening tables | 0.000056 |
| setup | 0.000033 |
| creating table | 0.088857 |
| After create | 0.009908 |
| System lock | 0.000017 |
| preparing for alter table | 0.022311 |
| altering table | 0.083790 |
| committing alter table to stor | 0.173121 |
| end | 0.000042 |
| query end | 0.000072 |
| closing tables | 0.000013 |
| freeing items | 0.003677 |
| cleaning up | 0.000038 |
+--------------------------------+----------+
17 rows in set, 1 warning (0.03 sec)

mysql> drop table xs;


Query OK, 0 rows affected (0.04 sec)

mysql> create table xs(name varchar(12),age int default 5);
Query OK, 0 rows affected (0.20 sec)

mysql> insert into xs values('a',4);
Query OK, 1 row affected (0.00 sec)

mysql> alter table xs alter column age set default 3;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> show profiles;
+----------+------------+-----------------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+-----------------------------------------------------+
| 2 | 0.00445825 | alter table xs alter column age set default 3 |
+----------+------------+-----------------------------------------------------+
8 rows in set, 1 warning (0.00 sec)

mysql> show profile for query 2;
+--------------------------------+----------+
| Status | Duration |
+--------------------------------+----------+
| starting | 0.000058 |
| checking permissions | 0.000006 |
| checking permissions | 0.000006 |
| init | 0.000003 |
| Opening tables | 0.000040 |
| setup | 0.000024 |
| creating table | 0.003538 |
| After create | 0.000160 |
| System lock | 0.000019 |
| preparing for alter table | 0.000004 |
| altering table | 0.000016 |
| committing alter table to stor | 0.000364 |
| end | 0.000021 |
| query end | 0.000048 |
| closing tables | 0.000008 |
| freeing items | 0.000128 |
| cleaning up | 0.000020 |
+--------------------------------+----------+
17 rows in set, 1 warning (0.00 sec)

********************************************************************************************************

5.1版本中

mysql> create table xs(name varchar(12),age int default 5);
Query OK, 0 rows affected (0.02 sec)

mysql> insert into xs values('a',4);
Query OK, 1 row affected (0.00 sec)

mysql> set profiling=1;
Query OK, 0 rows affected (0.00 sec)

mysql> alter table xs modify age int not null default 3;
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0

mysql> show profiles;
+----------+------------+--------------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+--------------------------------------------------+
| 1 | 0.00469700 | alter table xs modify age int not null default 3 |
+----------+------------+--------------------------------------------------+
1 row in set (0.00 sec)

mysql> show profile for query 1;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000063 |
| checking permissions | 0.000002 |
| checking permissions | 0.000005 |
| init | 0.000036 |
| Opening tables | 0.000008 |
| System lock | 0.000003 |
| Table lock | 0.000008 |
| setup | 0.000023 |
| creating table | 0.004031 |
| After create | 0.000076 |
| copy to tmp table | 0.000152 |
| rename result table | 0.000238 |
| end | 0.000026 |
| query end | 0.000003 |
| freeing items | 0.000021 |
| cleaning up | 0.000002 |
+----------------------+----------+
16 rows in set (0.00 sec)

mysql> drop table xs;
Query OK, 0 rows affected (0.00 sec)

mysql> create table xs(name varchar(12),age int default 5);
Query OK, 0 rows affected (0.00 sec)

mysql> insert into xs values('a',4);
Query OK, 1 row affected (0.00 sec)

mysql> alter table xs alter column age set default 3;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> show profiles;
+----------+------------+-----------------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+-----------------------------------------------------+
| 1 | 0.00469700 | alter table xs modify age int not null default 3 |
| 2 | 0.00023300 | drop table xs |
| 3 | 0.00527100 | create table xs(name varchar(12),age int default 5) |
| 4 | 0.00030300 | insert into xs values('a',4) |
| 5 | 0.00403400 | alter table xs alter column age set default 3 |
+----------+------------+-----------------------------------------------------+
5 rows in set (0.00 sec)

mysql> show profile for query 5;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000041 |
| checking permissions | 0.000003 |
| checking permissions | 0.000004 |
| init | 0.000034 |
| Opening tables | 0.000009 |
| System lock | 0.000004 |
| Table lock | 0.000015 |
| setup | 0.000028 |
| creating table | 0.003599 |
| After create | 0.000011 |
| manage keys | 0.000003 |
| rename result table | 0.000241 |
| end | 0.000021 |
| query end | 0.000003 |
| freeing items | 0.000017 |
| cleaning up | 0.000001 |
+----------------------+----------+
16 rows in set (0.00 sec)

alter column和modify column的更多相关文章

  1. mysql之ALTER COLUMN、CHANGE COLUMN、MODIFY COLUMN的区别

    ALTER COLUMN:设置或删除列的默认值(操作速度非常快) 例子: alter table film alter column rental_duration set default 5; al ...

  2. MySQL:ALTER COLUMN、MODIFY COLUMN 和 CHANGE COLUMN

    ALTER COLUMN.MODIFY COLUMN 和 CHANGE COLUMN 语句修改列: ALTER COLUMN:改变.删除列的默认值(备注:列的默认值存储在 .frm 文件中). 这个语 ...

  3. MySQL之 ALTER vs CHANGE vs MODIFY COLUMN

    1.ALTER COLUMN 用于设置或者移除某一列的默认(缺省)值, 1.1用法 ALTER TABLE MyTable ALTER COLUMN foo SET DEFAULT 'bar'; AL ...

  4. MySQL ALTER TABLE: ALTER vs CHANGE vs MODIFY COLUMN

    ALTER COLUMN 语法: ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT} 作用: 设置或删除列的默认值.该操作会直接修 ...

  5. Modify column Vs change column

    引言 I know, we can not rename a column using modify column syntax,but can change column syntax. My qu ...

  6. mysql ALTER COLUMN MODIFY COLUMN CHANGE COLUMN 区别及用法 (转)

    -- 设置或删除列的默认值.该操作会直接修改.frm文件而不涉及表数据.此操作很快 -- ALTER COLUMN ALTER TABLE  dsp_ad_center.XianDuan ALTER  ...

  7. alter table fx.pet modify column `species` varchar(20) binary;

    alter table fx.pet modify column `species` varchar(20) binary;

  8. Oracle alter table modify column Syntax example

    http://www.dba-oracle.com/t_alter_table_modify_column_syntax_example.htm For complete tips on Oracle ...

  9. DB2—alter追加/删除/重置column操作

    DB2—alter追加/删除/重置column操作   1.添加字段   alter table 表名称 add 字段名称 类型   Demo: 1 alter table table_name  a ...

随机推荐

  1. 黑马2020JAVA-会员版课程

    感谢@匿名网友的投稿 投稿人留言:这套教程是我花钱买来的,免费分享供大家参考 最新版的黑马java教程,喜欢编程的朋友可以学习下! 百度网盘: https://pan.baidu.com/s/14AY ...

  2. Oh my God, Swagger API文档竟然可以这样写?

    最好的总会在不经意间出现. 作为后端程序员,免不了与前端同事对接API, 一个书写良好的API设计文档可有效提高与前端对接的效率. 为避免联调时来回撕逼,今天我们聊一聊正确使用Swaager的姿势. ...

  3. Sql Server 数据把列根据指定的内容拆分数据

    今天由于工作需要,需要把数据把列根据指定的内容拆分数据 其中一条数据实例 select id , XXXX FROM BIZ_PAPER where  id ='4af210ec675927fa016 ...

  4. Spark SQL 小文件问题处理

    在生产中,无论是通过SQL语句或者Scala/Java等代码的方式使用Spark SQL处理数据,在Spark SQL写数据时,往往会遇到生成的小文件过多的问题,而管理这些大量的小文件,是一件非常头疼 ...

  5. oracle 常用语句2

    -- number(38) -- char(2000) -- varchar(4000) create table student( sno number(3) primary key, sname ...

  6. matplotlib的学习6-annotation的标注

    import matplotlib.pyplot as plt import numpy as np ''' 当图线中某些特殊地方需要标注时,我们可以使用 annotation. matplotlib ...

  7. WP | [MRCTF2020]Ezpop

    2020.10.14 最近开始努力提高代码能力 题目代码 Welcome to index.php <?php //flag is in flag.php //WTF IS THIS? //Le ...

  8. Azure Databricks 第一篇:创建工作区、集群和Notebook

    Azure Databricks是一个可扩展的数据分析平台,基于Apache Spark.Azure Databricks 工作区(Workspace)是一个交互式的环境,工作区把对象(noteboo ...

  9. 使用IDE练习插件【廖雪峰】

    使用廖雪峰大神的插件,安装过程中,一直出现问题,然后在他的Java教程下面看大家的评论也有点晕了(很多人说的是jar包,结果其实是下的依旧是zip包) 最终解决方法: 将zip包解压到同名文件夹中,再 ...

  10. 深入浅出!阿里P7架构师带你分析ArrayList集合源码,建议是先收藏再看!

    ArrayList简介 ArrayList 是 Java 集合框架中比较常用的数据结构了.ArrayList是可以动态增长和缩减的索引序列,内部封装了一个动态再分配的Object[]数组 这里我们可以 ...