Insert data into multiple tables via sql view

Is there a way to insert data into multiple tables through a view in mysql?

+4
source share
2 answers

The MySQL Reference Guide talks about updatable views:

Some views are being updated. That is, you can use them in expressions such as UPDATE , DELETE or INSERT to update the contents of the underlying table. For the view to be updatable, there must be a one-to-one relationship between the rows in the view and the rows in the base table. There are also some other designs that make viewing unchanged.

The WITH CHECK OPTION clause can be specified for an updatable view to prevent inserts or updates to rows other than those for which the WHERE in select_statement is true. The WITH CHECK OPTION clause is implemented in MySQL 5.0.2.

You can find the whole article here .

+3
source

See this part of the MySQL reference manual:

It is sometimes possible that a view with multiple tables can be updated, assuming that it can be processed using the MERGE algorithm. For this to work, the view must use an internal join (and not an external join or UNION). In addition, only one table in a view definition can be updated, so the SET clause should specify only columns from one of the tables in the view. Views that use UNION ALL are not allowed, even though they can be theoretically updated, since the implementation uses temporary tables to process them.

For a multi-step updatable view, INSERT can work if it inserts into a single table. DELETE is not supported.

INSERT DELAYED is not supported for views.

+1
source

Source: https://habr.com/ru/post/1311055/


All Articles