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

  • 相关阅读:
    解决mac os x下 tomcat启动报 java.net.BindException: Permission denied <null>:80 错误
    Mac下MySQL卸载方法 转载
    利用JS函数制作时钟运行程序
    HTML页面弹出窗口调整代码总结
    JavaScript代码放在HTML代码不同位置的差别
    二十五种网页加速方法和seo优化技巧
    web前端之Html和Css应用中的细节问题
    利用css制作横向和纵向时间轴
    利用html5看雪花飘落的效果
    利用jQuery实现鼠标滑过整行变色
  • 原文地址:https://www.cnblogs.com/LMySQL/p/5699800.html
Copyright © 2011-2022 走看看