view


definition:

A view is a table derived from one or more tables (or views). A view is different from a table (sometimes it is different from a view, also known as a basic table - Base Table), a view is a virtual table, that is, the data corresponding to the view is not actually stored, and only the definition of the view is stored in the database. When the data of the view is operated, the system operates the basic table associated with the view according to the definition of the view.

operate:

1.

WITH check OPTION means that when performing UPDATE, INSERT, and delete operations on a view, it is necessary to ensure that the updated, deleted, or inserted rows satisfy the predicate conditions in the view definition.
Since the view is a virtual table that does not actually store data, the update to the view must be converted eventually. for updates to the base table. Therefore, in order to prevent users from operating on the data intentionally or unintentionally, you can add the with check option when defining the view.

2
If the view definition has the following clause, it cannot be updated

● Use group by and Having for grouping

● link

● Subqueries

● Union

● Aggregate function MAX MIN COUNT AVG

● DISTINCT

● Export columns

For example:
Because the update of the view will eventually be mapped to the update of the base table, but the fields in the view may not exist in the database (fields obtained from the base table through the aggregate function), so the update operation will be abnormal.

evaluate:

advantage:

Simplify user operations

Provides a certain degree of logical independence for refactoring the database

safety

shortcoming:

Modify restrictions

Performance issues, because the operations of the view are mapped to the base table, and the complexity of the view definition can lead to the complexity of the query operation.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325391406&siteId=291194637