Post

Database System - Basic SQL

Database System - Basic SQL

View

A view is either a partial reference (i.e., not the whole table) to or a read-only view upon some table.

Updatable view and read-only view

If a view satisfy the following conditions, it’s updatable:

  • Every row in the view can be uniquely mapped to a row in one table.
  • Columns in the view should not be expression. (e.g. SELECT a.id + 1 FROM a;)

Create a view

1
2
3
4
CREATE VIEW <VIEW> [(<COLUMN1> <COLUMN2> ... <COLUMNn>)]
AS
<SELECT_QUERY>
[WITH CHECK OPTION]
  • WITH CHECK OPTION ensures the rows won’t disappear after some view updates.

When a row is modified through a view, the WITH CHECK OPTION makes sure the data remains visible through the view after the modification is committed.

TODO 视图的作用

See also CMU 15-445 (2025 Fall) Model SQL.

This post is licensed under CC BY 4.0 by the author.