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的特性

  • 相关阅读:
    MPS和MRP之间有什么样的关系呢
    java中静态代码块详解
    SQL server 分组后每组取出任意一行
    人是否能成功,其实可能很早就能看出来
    国内外产品经理的区别
    Yarn 和 NPM 国内快速镜像(淘宝镜像)
    vue-cli 使用less 遇到的问题 || vue-cli 使用less
    布隆过滤器
    PHP性能优化
    Redis-高并发代言词,为什么做分布式要Redis?
  • 原文地址:https://www.cnblogs.com/LMySQL/p/5699800.html
Copyright © 2011-2022 走看看