ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 尝试了一下mysql的视图,主要是想解决分表后的统计不会太麻烦的问题

尝试了一下mysql的视图,主要是想解决分表后的统计不会太麻烦的问题

原创 Linux操作系统 作者:bulletming 时间:2019-05-18 09:39:05 1 删除 编辑

mysql> create view abc as select * from free_space union all select * from free_space;
Query OK, 0 rows affected (3.81 sec)

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| abc            |
| free_space     |
+----------------+
2 rows in set (0.00 sec)

mysql> show create view abc;
+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| View | Create View                                                                                                                                                                                           |
+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| abc  | CREATE ALGORITHM=UNDEFINED DEFINER=`ADMIN`@`localhost` SQL SECURITY DEFINER VIEW `abc` AS select `free_space`.`a` AS `a` from `free_space` union all select `free_space`.`a` AS `a` from `free_space` |
+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select * from abc;
Empty set (0.01 sec)

mysql> insert into abc values(1);
ERROR 1471 (HY000): The target table abc of the INSERT is not insertable-into
mysql>
mysql>
mysql> insert into free_space values(1);
Query OK, 1 row affected (1.27 sec)

mysql> select * from abc;
+------+
| a    |
+------+
|    1 |
|    1 |
+------+
2 rows in set (0.00 sec)

mysql> insert into free_space values(2);
Query OK, 1 row affected (1.83 sec)

mysql> select * from abc;
+------+
| a    |
+------+
|    1 |
|    2 |
|    1 |
|    2 |
+------+
4 rows in set (0.00 sec)

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/82392/viewspace-155676/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: perl替换特殊字符
请登录后发表评论 登录
全部评论

注册时间:2004-05-31

  • 博文量
    121
  • 访问量
    106597