本文將介紹如何使用CREATE VIEW語句為PolarDB-X 1.0創(chuàng)建視圖。

前提條件

PolarDB-X 1.0實例版本需為5.4.5或以上,關(guān)于如何查看實例版本,請參見實例版本概覽

語法

CREATE
    [OR REPLACE]
    VIEW view_name [(column_list)]
    AS select_statement

示例

# 先建表
CREATE TABLE t_order (
  `id` bigint(11) NOT NULL AUTO_INCREMENT,
  `order_id` varchar(20) DEFAULT NULL,
  `buyer_id` varchar(20) DEFAULT NULL,
  `seller_id` varchar(20) DEFAULT NULL,
  `order_snapshot` longtext DEFAULT NULL,
  `order_detail` longtext DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `l_i_order` (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 dbpartition by hash(`order_id`);

# 創(chuàng)建視圖
create view t_detail as select order_id,order_detail from t_order;

# 查詢視圖
select * from t_detail;