管理mysql的檢視
Summary: in this tutorial, you will learn how to manage views in MySQL including displaying, modifying and removing views.
Show view definition in MySQL
MySQL provides the SHOW CREATE VIEW
statement that helps you show view definition. The following is the syntax of the SHOW CREATE VIEW
statement:
SHOW CREATE VIEW [database_name].[view_ name];
To display the definition of a view, you just need to specify its name after the SHOW CREATE VIEW
keywords.
Let’s for the demonstration.
First, we create a simple view against the employees
table that displays the company’s organization structure:
CREATE VIEW organization AS SELECT CONCAT (E.lastname,E.firstname) AS Employee, CONCAT (M.lastname,M.firstname) AS Manager FROM employees AS E INNER JOIN employees AS M ON M.employeeNumber = E.ReportsTo ORDER BY Manager
To display the view’s definition, you use the SHOW CREATE VIEW
statement as follows:
SHOW CREATE VIEW organization
You can also display the definition of the view by using any plain text editor such as notepad to open the view definition file in the database folder.
For example, to open the organization
view definition, you can find the view definition file with the following path: dataclassicmodelsorganization.frm
Modifying views
Once a view is defined, you can modify it by using the ALTER VIEW
statement. The syntax of the ALTER VIEW
statement is similar to the CREATE VIEW
statement except the CREATE
keyword is replaced by the ALTER
keyword.
ALTER [ALGORITHM = {MERGE | TEMPTABLE | UNDEFINED}] VIEW [database_name]. [view_name] AS [SELECT statement]
The following query modifies the organization
view by adding an addition email
field.
ALTER VIEW organization AS SELECT CONCAT(E.lastname,E.firstname) AS Employee, E.email AS employeeEmail, CONCAT(M.lastname,M.firstname) AS Manager FROM employees AS E INNER JOIN employees AS M ON M.employeeNumber = E.ReportsTo ORDER BY Manager
To verify the change, you can query data from the organization
view:
SELECT * FROM Organization
MySQL drop views
Once a view created, you can remove it by using the DROP VIEW
statement. The following illustrates the syntax of the DROP VIEW
statement:
DROP VIEW [IF EXISTS] [database_name].[view_name]
The IF EXISTS
is the optional element of the statement, which allows you to check whether the view exists or not. It helps you avoid an error of removing a non-existent view.
For example, if you want to remove the organization
view, you can use the DROP VIEW
statement as follows:
DROP VIEW IF EXISTS organization
Each time you modify or remove a view, MySQL makes a back up of the view definition file to the /database_name/arc/
folder. In case you modify or remove a view by accident, you can get a back up from there.
In this tutorial, you have learned how to manage views in MySQL including displaying, modifying and removing views.
Related Tutorials
原文連結:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/4422/viewspace-2805742/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MYSQL 檢視MySql
- MySQL View 檢視MySqlView
- 檢視MySQL鎖等待的原因MySql
- MySQL 查詢的成本的檢視MySql
- MySQL檢視介紹MySql
- MySQL 檢視簡介MySql
- 10_MySQL檢視MySql
- 檢視mysql版本的六種方法MySql
- MySQL入門系列:檢視MySql
- mysql建立索引和檢視MySql索引
- MySql 什麼是檢視MySql
- MySQL之檢視學習MySql
- MySQL筆記 13 檢視MySql筆記
- MySQL全面瓦解15:檢視MySql
- 【MySQL】檢視&子查詢MySql
- 怎麼檢視mysql的儲存引擎MySql儲存引擎
- MySQL檢視簡介與操作MySql
- MySQL檢視建表語句MySql
- 如何檢視mysql目錄在哪MySql
- MySQL檢視和修改字符集的方法MySql
- 檢視使用 MySQL Shell 的連線狀態MySql
- linux下檢視mysql版本的四種方法LinuxMySql
- 怎樣檢視mysql的安裝目錄MySql
- 怎麼檢視mysql的安裝路徑MySql
- mysql檢視主從同步狀態的方法MySql主從同步
- 檢視mysql 的binlog日誌存放的位置(轉)MySql
- mysql 聯合表(federated)及檢視MySql
- navicat檢視mysql安裝位置命令MySql
- [MySQL光速入門]028 聊聊檢視MySql
- 22. 使用MySQL之使用檢視MySql
- mysql binlog檢視指定資料庫MySql資料庫
- mysql檢視binlog日誌詳解MySql
- MySQL:如何快速的檢視Innodb資料檔案MySql
- MySQL檢視版本號的五種方式介紹MySql
- 【Mongo】MongoDB索引管理-索引的建立、檢視、刪除MongoDB索引
- 11 UML中的邏輯檢視、程序檢視、實現檢視、部署檢視
- linux檢視mysql佔用磁碟空間LinuxMySql
- MySQL--儲存過程與檢視MySql儲存過程