SQLite Advanced -17. View

View (View)

Views is present in the form of a predefined query SQLite combination table.

It may comprise a table of all rows or selected tables from one or more rows. From one or more tables, depending on the view creation statement.

View (View) is a virtual table, it is read-only, and can not perform DELETE, INSERT or UPDATE statement on a view. But you can create a trigger, when the DELETE, INSERT or UPDATE operation occurs on view, it needs to be done to achieve operating within triggers.

-- 语句
CREATE [TEMP | TEMPORARY] VIEW view_name AS
    SELECT column1, column2..
    FROM table_name
    WHERE [condition];
-- SELECT 语句可以操作多个表。
-- 关键字TEMP 或 TEMPORARY 用于创建临时视图。

-- 实例
CREATE VIEW link_men_view AS
    SELECT ID, NAME
    FROM link_name;

View of the scene using e.g.

  1. When customers need to access your data, and you do not want to expose all field values, it can be used.
  2. When a requirement needs to query multiple tables, you can create a view for temporary use.

Action view

Like ordinary operating table

SELECT * FROM link_men_view;

Update View

OR REPLACE keyword, if the current view of the specified database name already exists, the view currently being created will overwrite the original view of the same name.

-- 语句
CREATE  OR REPLACE VIEW view_name AS
    SELECT column1, column2..
    FROM table_name
    WHERE [condition];

-- 实例
CREATE OR REPLACE VIEW link_men_view AS
    SELECT ID, NAME
    FROM link_name;

Delete View

DROP VIEW link_men_view;

View all views

The following statement is to be executed at the command line.

select * from sqlite_master where type='view';

Guess you like

Origin www.cnblogs.com/haitao130v/p/11372047.html