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. React中对render进行的小优化

    react中state和props变化会造成render的重新渲染,有时候我们会在render函数中进行一些稍微复杂的逻辑运算 比如说,像下边这种 在props中将 industries引入,然后对其 ...

  2. Day4 dict和set

    dict  -- dictionary    一组key的集合,包含key与value的对应.        Python内置的字典,在其他语言中称为map,使用key-value存储,具有极快的查找 ...

  3. JavaSE11-多态&抽象类&接口

    1.多态 1.1 多态的概述 什么是多态 同一个对象,在不同时刻表现出来的不同形态 多态的前提 要有继承或实现关系 要有方法的重写 要有父类引用指向子类对象 1.2 多态中的成员访问特点 成员访问特点 ...

  4. [从源码学设计]蚂蚁金服SOFARegistry之时间轮的使用

    [从源码学设计]蚂蚁金服SOFARegistry之时间轮的使用 目录 [从源码学设计]蚂蚁金服SOFARegistry之时间轮的使用 0x00 摘要 0x01 业务领域 1.1 应用场景 0x02 定 ...

  5. VSCode---REST Client接口测试辅助工具

    我们一般都会用 PostMan 来完成接口测试的工作,因为用起来十分简单快捷,但是一直以来我也在寻找更好的方案,一个不用切换窗口多开一个 app 的方案 -- 终于在使用 VSCode 一段时版本间, ...

  6. 对着爬虫网页HTML学习Python正则表达式re

    1.正则表达式初探 用比较经典的例子,查找一段文本中的手机号码.比如对于文本"我现在用的电话是188-8888-8888,之前那个186-6666-6666已经不用了",我们想获取 ...

  7. Python自动化办公第三方库xlwt

    Python向excel表格写入内容,首先安装第三方库: pip3 install xlwt 代码实例(结合xlrd): #!usr/bin/env python3 #!-*-coding=utf-8 ...

  8. OSPF --- 不规则区域实验

    OSPF不规则区域实验: 一.知识点整理: OSPF中路由器的角色(看图): 骨干路由器:路由器所有接口属于area 0  -->R3 非骨干路由器:路由器所有接口属于非area 0  --&g ...

  9. python三大流程

    一.三大流程 1. 顺序:按照顺序依次逐行执行代码的过程.自左向右,自上而下 2. 分支:程序按照不同的条件执行不同的处理代码的过程. 分支分为单分支,双分支,多分支 经常用到的分支结构是if语句 i ...

  10. 7.mysql8.0版本MGR搭建

    搭建MGR 1.配置文件 loose-group_replication_ip_whitelist = 192.168.124.0/24 loose-group_replication_start_o ...