Create and modify MySQL view charts

Source: Internet
Author: User
Tags mysql view
1. CREATE [ORREPLACE] [lt; algorithmattributesgt;] VIEW [database.] lt; namegt; [(lt; columnsgt;)] ASlt; selec

1. CREATE [or replace] [lt; algorithm attributesgt;] VIEW [database.] lt; namegt; [(lt; columnsgt;)] AS lt; selec

1. Create

CREATE [or replace] [] VIEW [database.] <name> [( )]
AS []Example:Create view 'view _ articles'ASSELECTA. id AS id,A. title AS title,A. content AS content,T. name AS tagname,U. firstname AS "username"FROM 'articles'aLeft join 'tags' tON a. tag_id = t. idLeft join 'users' uON a. user_id = u. idOrder by a. posttime DESC;ModifyALTER [] VIEW [.] <Name> [()]AS[ ]

Alter view 'view _ articles'
A. id AS id,
A. title AS title,
A. content AS content,
A. posttime AS posttime,
T. name AS tagname,
CONCAT (u. firstname, '', u. lastname) AS" username"
FROM 'articles'a
Left join 'tags' t
ON a. tag_id = t. id
Left join 'users' u
ON a. user_id = u. id
Order by a. posttime DESC;

The easiest way to modify a created visual chart is to export the SQL statement of the visual chart in phpMyAdmin, then modify the "CREATE" at the beginning (the "ALGORITHM = undefined definer = 'root' @ 'localhost' SQL SECURITY DEFINER" at the end) to "ALTER ", run the statement.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.