MySQL 建立檢視
MariaDB [test]> CREATE TABLE t (qty INT, price INT);
Query OK, 0 rows affected (0.15 sec)
MariaDB [test]> INSERT INTO t VALUES(3, 50);
Query OK, 1 row affected (0.01 sec)
--建立檢視
MariaDB [test]> CREATE VIEW v AS SELECT qty, price, qty*price AS value FROM t;
Query OK, 0 rows affected (0.09 sec)
MariaDB [test]> SELECT * FROM v;
+------+-------+-------+
| qty | price | value |
+------+-------+-------+
| 3 | 50 | 150 |
+------+-------+-------+
1 row in set (0.00 sec)
MariaDB [test]> explain select * from v;
+------+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+-------+
| 1 | SIMPLE | t | ALL | NULL | NULL | NULL | NULL | 1 | |
+------+-------------+-------+------+---------------+------+---------+------+------+-------+
1 row in set (0.00 sec)
--檢視檢視狀態
MariaDB [test]> show table status from test like 'v'\G
*************************** 1. row ***************************
Name: v
Engine: NULL
Version: NULL
Row_format: NULL
Rows: NULL
Avg_row_length: NULL
Data_length: NULL
Max_data_length: NULL
Index_length: NULL
Data_free: NULL
Auto_increment: NULL
Create_time: NULL
Update_time: NULL
Check_time: NULL
Collation: NULL
Checksum: NULL
Create_options: NULL
Comment: VIEW
1 row in set (0.00 sec)
--檢視建立語句
MariaDB [test]> show create view v\G
*************************** 1. row ***************************
View: v
Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select `t`.`qty` AS `qty`,`t`.`price` AS `price`,(`t`.`qty` * `t`.`price`) AS `value` from `t`
character_set_client: utf8
collation_connection: utf8_general_ci
MariaDB [test]> select * from information_schema.views where table_name = 'v'\G
*************************** 1. row ***************************
TABLE_CATALOG: def
TABLE_SCHEMA: test
TABLE_NAME: v
VIEW_DEFINITION: select `test`.`t`.`qty` AS `qty`,`test`.`t`.`price` AS `price`,(`test`.`t`.`qty` * `test`.`t`.`price`) AS `value` from `test`.`t`
CHECK_OPTION: NONE
IS_UPDATABLE: YES
DEFINER: root@localhost
SECURITY_TYPE: DEFINER
CHARACTER_SET_CLIENT: utf8
COLLATION_CONNECTION: utf8_general_ci
ALGORITHM: UNDEFINED
1 row in set (0.02 sec)
Query OK, 0 rows affected (0.15 sec)
MariaDB [test]> INSERT INTO t VALUES(3, 50);
Query OK, 1 row affected (0.01 sec)
--建立檢視
MariaDB [test]> CREATE VIEW v AS SELECT qty, price, qty*price AS value FROM t;
Query OK, 0 rows affected (0.09 sec)
MariaDB [test]> SELECT * FROM v;
+------+-------+-------+
| qty | price | value |
+------+-------+-------+
| 3 | 50 | 150 |
+------+-------+-------+
1 row in set (0.00 sec)
MariaDB [test]> explain select * from v;
+------+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+-------+
| 1 | SIMPLE | t | ALL | NULL | NULL | NULL | NULL | 1 | |
+------+-------------+-------+------+---------------+------+---------+------+------+-------+
1 row in set (0.00 sec)
--檢視檢視狀態
MariaDB [test]> show table status from test like 'v'\G
*************************** 1. row ***************************
Name: v
Engine: NULL
Version: NULL
Row_format: NULL
Rows: NULL
Avg_row_length: NULL
Data_length: NULL
Max_data_length: NULL
Index_length: NULL
Data_free: NULL
Auto_increment: NULL
Create_time: NULL
Update_time: NULL
Check_time: NULL
Collation: NULL
Checksum: NULL
Create_options: NULL
Comment: VIEW
1 row in set (0.00 sec)
--檢視建立語句
MariaDB [test]> show create view v\G
*************************** 1. row ***************************
View: v
Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select `t`.`qty` AS `qty`,`t`.`price` AS `price`,(`t`.`qty` * `t`.`price`) AS `value` from `t`
character_set_client: utf8
collation_connection: utf8_general_ci
MariaDB [test]> select * from information_schema.views where table_name = 'v'\G
*************************** 1. row ***************************
TABLE_CATALOG: def
TABLE_SCHEMA: test
TABLE_NAME: v
VIEW_DEFINITION: select `test`.`t`.`qty` AS `qty`,`test`.`t`.`price` AS `price`,(`test`.`t`.`qty` * `test`.`t`.`price`) AS `value` from `test`.`t`
CHECK_OPTION: NONE
IS_UPDATABLE: YES
DEFINER: root@localhost
SECURITY_TYPE: DEFINER
CHARACTER_SET_CLIENT: utf8
COLLATION_CONNECTION: utf8_general_ci
ALGORITHM: UNDEFINED
1 row in set (0.02 sec)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2121331/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql建立索引和檢視MySql索引
- Laravel 通過遷移指令碼建立MySQL檢視Laravel指令碼MySql
- Laravel 透過遷移指令碼建立MySQL檢視Laravel指令碼MySql
- MYSQL 檢視MySql
- MySQL View 檢視MySqlView
- MySQL檢視介紹MySql
- 管理mysql的檢視MySql
- MySQL 檢視簡介MySql
- 10_MySQL檢視MySql
- Git檢視分支建立時間Git
- MySQL入門系列:檢視MySql
- MySql 什麼是檢視MySql
- MySQL之檢視學習MySql
- MySQL筆記 13 檢視MySql筆記
- MySQL全面瓦解15:檢視MySql
- 【MySQL】檢視&子查詢MySql
- MySQL檢視簡介與操作MySql
- MySQL檢視建表語句MySql
- 檢視MySQL鎖等待的原因MySql
- 如何檢視mysql目錄在哪MySql
- Oracle物化檢視的建立及使用(二)Oracle
- Oracle物化檢視的建立及使用(一)Oracle
- Git檢視tag標籤建立時間Git
- laravel利用artisan建立view檢視檔案LaravelView
- 達夢資料庫建立檢視&MyBatis表能不能關聯檢視資料庫MyBatis
- mysql 聯合表(federated)及檢視MySql
- navicat檢視mysql安裝位置命令MySql
- [MySQL光速入門]028 聊聊檢視MySql
- 檢視mysql版本的六種方法MySql
- 22. 使用MySQL之使用檢視MySql
- mysql binlog檢視指定資料庫MySql資料庫
- MySQL 查詢的成本的檢視MySql
- mysql檢視binlog日誌詳解MySql
- oracle db link的檢視建立與刪除Oracle
- Android開發 - inflate方法與建立檢視解析Android
- [20211206]toad下job建立檢視問題.txt
- [20210423]建立檢視以及欄位長度.txt
- linux檢視mysql佔用磁碟空間LinuxMySql
- MySQL--儲存過程與檢視MySql儲存過程