zoukankan      html  css  js  c++  java
  • MariaDB10.2.X-新特性2-支持check约束and with as

    前几天写了一篇MariaDB10.2支持分析函数,大家印象中MySQL不支持with as ,check约束,那么MariaDB10.2也同样给你惊喜

    1.with as

    MariaDB [test11]> with a as ( select * from t1 where channerId ='支付宝' )  select * from a;

    +----+--------+------------+-----------+--------+

    | id | userId | orderId    | channerId | amount |

    +----+--------+------------+-----------+--------+

    |  1 | 张3    | 2016060101 | 支付宝    |    100 |

    |  2 | 李4    | 2016060102 | 支付宝    |     98 |

    |  7 | 张3    | 2016060107 | 支付宝    |    200 |

    | 10 | 李4    | 2016060110 | 支付宝    |    300 |

    +----+--------+------------+-----------+--------+

    4 rows in set (0.01 sec)

    MariaDB [test11]> explain with a as ( select * from t1 where channerId ='支付宝' )  select * from a;

    +------+-------------+-------+------+---------------+---------------+---------+-------+------+-----------------------+

    | id   | select_type | table | type | possible_keys | key           | key_len | ref   | rows | Extra                 |

    +------+-------------+-------+------+---------------+---------------+---------+-------+------+-----------------------+

    |    1 | SIMPLE      | t1    | ref  | idx_channerId | idx_channerId | 182     | const |    4 | Using index condition |

    +------+-------------+-------+------+---------------+---------------+---------+-------+------+-----------------------+

    1 row in set (0.00 sec)

    MariaDB [test11]>

    #check 约束

    MariaDB [test11]> CREATE TABLE `t_user` (

        -> `id`  int NOT NULL AUTO_INCREMENT ,

        -> `name`  varchar(255) NOT NULL DEFAULT '' ,

        -> `age`  tinyint UNSIGNED NULL check(age > 0 and age < 120)  ,

        -> `gender`  tinyint NULL COMMENT '(0男,1女,2未知)' ,

        -> `address`  varchar(255) NULL ,

        -> PRIMARY KEY (`id`)

        -> )

        -> ;

    Query OK, 0 rows affected (0.03 sec)

    MariaDB [test11]> insert into t_user  ( name,age,gender,address) values ( 'zhangsan',1,1,'afdadfa');

    Query OK, 1 row affected (0.03 sec)

    MariaDB [test11]> insert into t_user  ( name,age,gender,address) values ( 'lisi',121,0,'afdadfa');

    ERROR 4022 (23000): CONSTRAINT `age` failed for `test11`.`t_user`

    MariaDB [test11]> insert into t_user  ( name,age,gender,address) values ( 'lisi',0,0,'afdadfa');

    ERROR 4022 (23000): CONSTRAINT `age` failed for `test11`.`t_user`

    MariaDB [test11]> update t_user set age =122 where id =1;
    ERROR 4022 (23000): CONSTRAINT `age` failed for `test11`.`t_user`
    MariaDB [test11]>

    ###

    这个很值得期待的版本,希望官方版本也能及时跟进,纵观MySQL5.6,5.7的很多特性都是借鉴MariaDB的特性

  • 相关阅读:
    python读取csv文件、excel文件并封装成dict类型的list,直接看代码
    利用Python获取cookie的方法,相比java代码简便不少
    关于appium操作真机打开app之后无法定位页面元素的问题的解决办法
    关于做移动端ui自动化测试使用PC代理网络会出现的问题
    接口测试面试问题总结-转载
    接口测试3-参数关联接口(从上一个接口中获取数据,访问幼儿园服务器接口无session)
    接口测试2-接口测试 get post请求
    HTTP协议
    接口测试1-概论
    python视频学习笔记8(函数返回值和参数进阶)
  • 原文地址:https://www.cnblogs.com/LMySQL/p/5699800.html
Copyright © 2011-2022 走看看