ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 数据库 >> 其他数据库 >> MariaDB扩展特性--动态列

MariaDB扩展特性--动态列(1/2)

来源:网络整理     时间:2016-04-16     关键词:mariadb

本篇文章主要介绍了"MariaDB扩展特性--动态列",主要涉及到mariadb方面的内容,对于其他数据库感兴趣的同学可以参考一下: 从版本5.3开始,MariaDB开始支持动态列,允许一个表的每一行存储不同列的信息。 使用动态列的前提是表中必须包含blob类型的列。 create tabl...

从版本5.3开始,MariaDB开始支持动态列,允许一个表的每一行存储不同列的信息。
使用动态列的前提是表中必须包含blob类型的列。
create table computer(
rid int not null auto_increment primary key,
product_name varchar(50),
product_attr blob
);

MariaDB [test]> insert into computer(product_name,product_attr) values("macbook pro",column_create("color","sliver","size","15.6","price","16000"));
Query OK, 1 row affected (0.01 sec)

MariaDB [test]> insert into computer(product_name,product_attr) values("surfacebook",column_create("color","sliver","keyboard","red","size","13","memory","8GB","price","12000"));
Query OK, 1 row affected (0.01 sec)

// 查询 

MariaDB [test]> select product_name, column_get(product_attr, "size" as char) as size from computer;
+--------------+------+
| product_name | size |
+--------------+------+
| macbook pro  | 15.6 |
| surfacebook  | 13   |
+--------------+------+
2 rows in set (0.00 sec)

// 删除 

MariaDB [test]> update computer set product_attr=column_delete(product_attr,"color") where column_get(product_attr,"keyboard" as char)="red";
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

// 新添 

MariaDB [test]> update computer set product_attr=column_add(product_attr, "year","2016") where product_name="macbook pro";
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0

// 查看动态列 

MariaDB [test]> select product_name, column_list(product_attr) from computer;
+--------------+------------------------------------+
| product_name | column_list(product_attr)          |
+--------------+------------------------------------+
| macbook pro  | `size`,`year`,`color`,`price`      |
| surfacebook  | `size`,`price`,`memory`,`keyboard` |
+--------------+------------------------------------+
2 rows in set (0.00 sec)

// 查看动态列及值(json格式) 

相关图片

相关文章