This article mainly introduces to you How to add new data to the view in the mysql data table.
The relevant knowledge of mysql views has been introduced to you in detail in our previous articles. I believe that everyone must have a deeper understanding of views.
From the introduction of the previous article, everyone should know that a view is a virtual table defined by a query composed of SELECT statements. It is composed of data in one or more tables. From outside the database system, A view is just like a data table. General operations that can be performed on the table can be applied to the view, such as querying, inserting data, modifying the view, deleting the view, etc.
When I need to insert new data into the view, how do I insert new data?
Below we will use a simple example to introduce how to insert new data in a single table view.
First we can use the command line tool to query the field information in the view.
SQL syntax for querying field information:
desc + 视图名 ;
As shown in the figure, there are only two fields id and name in the view my_v1 .
Then we insert a new data in the my_v1 view, the SQL statement is as follows:
As shown in the figure, we use the insert into statement to A new id and name data is inserted into the my_v1 view.
Let’s check whether the data is inserted successfully through Navicat.
As shown in the figure, the data in the my_v1 view has been successfully inserted. However, due to encoding problems, the "kitten" field cannot be displayed normally, so I will not go into details here. Later articles will explain the problem of mysql garbled code in detail for everyone.
In fact, when we insert data into the single-table view, the same data will also be inserted into the base table, which is the data table that makes up this view.
Note: Views that use the INSERT statement for insert operations must be able to insert data into the base table (the table that makes up the view query), Otherwise the operation will fail. When we insert new data into the data base table, the view will also insert data synchronously.
And data modification statements cannot be used on multiple underlying tables in one statement. Therefore, if you want to add data to a view that references multiple data tables, you must use multiple INSERT statements to add it.
This article is about adding new data to the mysql view. It is also very simple and easy to understand. I hope it will be helpful to friends in need!
If you want to know more about mysql, you can follow the PHP Chinese website mysql video tutorial, everyone is welcome to refer to and learn!
The above is the detailed content of How to add new data to Mysql view. For more information, please follow other related articles on the PHP Chinese website!