标签:
前几天写了一篇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的特性
MariaDB10.2.X-新特性2-支持check约束and with as
标签:
原文地址:http://www.cnblogs.com/LMySQL/p/5699800.html