Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the limitations of mysql updating views?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is about what the restrictions on updating views in mysql are. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. Some views are not updatable because updates to these views cannot be meaningfully converted to the corresponding base tables.

2. In general, you can update the row and row subset view. In addition to the column subset view, you can theoretically update some views.

Example

-- create view ldq_t1CREATE VIEW ldq_t1 ASSELECT * FROM t3WHERE id1 > 10 WITH CHECK OPTION;-- query all results SELECT * FROM ldq_t1; in ldq_t1-- create view ldq_t2CREATE VIEW ldq_t2 ASSELECT * FROM ldq_t1WHERE id1 < 30 WITH LOCAL CHECK OPTION;-- create view ldq_t3CREATE VIEW ldq_t3 ASSELECT * FROM ldq_t1WHERE id1 < 30 WITH CHECK OPTION -- Update view ldq_t2 (only data that exists in ldq_t2 can be updated) SELECT * FROM ldq_t2;-- View ldq_t2 current record UPDATE ldq_t2 SET id1=5 WHERE id2=22;-- can execute UPDATE ldq_t2 SET id1=35 WHERE id2=22; successfully-- will report an error CHECK OPTION failed (because the id2=22 record will disappear from ldq_t2 after the statement is executed) UPDATE ldq_t2 SET id1=28 WHERE id2=22 -- can execute successfully-- Update ldq_t3SELECT * FROM ldq_t3;UPDATE ldq_t3 SET id1=5 WHERE id2=22;-- will report an error CHECK OPTION failed (because after the data update, you must also ensure that it is still in ldq_t3 and ldq_t1, and the id2=22 record will disappear from ldq_t1 after the statement is executed) UPDATE ldq_t3 SET id1=15 WHERE id2=22;-- can execute UPDATE ldq_t3 SET id1=35 WHERE id2=22 successfully. -- an error CHECK OPTION failed will be reported (because the id2=22 record will disappear from the ldq_t3 after the execution of this statement) DELETE FROM ldq_t3 WHERE id2=22;-- successful execution Thank you for reading! This is the end of this article on "what are the restrictions on updating views in mysql?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report