After mysql creates a view, it opens and prompts that there is no primary key

After the view is created, a dialog box prompts a message similar to the following:

update xxx ModefidedFiledsAndValues WHERE ALLFiledsAndOldValues LiMIT 1。

Create a view statement:

SELECT DISTINCT
cookbook.artist.a_id AS a_id,
cookbook.artist.`name` AS `name`
from `cookbook`.`artist`;

The view created by this statement has no problem with the query, but the update operation cannot be performed. The reason is DISTINCT. Just remove this.

Also have permissions. The following paragraph:

 

Some views are updatable. That is, they can be used in statements such as UPDATE , DELETE , or INSERT to update the contents of the base table. For an updatable view, there must be a one-to-one relationship between the rows in the view and the rows in the base table . There are certain other constructs that make the view non-updatable. More specifically, a view is not updatable if it contains any of the following structures:

         Aggregate functions ( SUM() , MIN()MAX()COUNT() etc.).

·         DISTINCT

·         GROUP BY

·         HAVING

·         UNIONUNION ALL

·          Subqueries in select lists

·         Join

non -          updatable views in the FROM clause

·          Subqueries in the WHERE clause, referencing tables in the FROM clause.

          Only literal values ​​are quoted (in this case, there is no base table to update).

·          ALGORITHM = TEMPTABLE (using a temporary table always makes the view not updatable) .

Regarding insertability (updating with an INSERT statement) , an updatable view is also insertable if it also meets the following additional requirements regarding view columns:

·          There must be no duplicate view column names.

· The          view must contain all columns in the base table without default values.

 

This passage is from: http://dev.mysql.com/doc/refman/5.1/en/views.html#alter-view

See here for details.

Guess you like

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