Home > Database > Mysql Tutorial > body text

MySQL视图表创建与修改

WBOY
Release: 2016-06-07 17:10:54
Original
2178 people have browsed it

1、创建 CREATE [OR REPLACE] [lt;algorithm attributesgt;] VIEW [database.]lt; namegt; [(lt;columnsgt;)]AS lt;selec

1、创建

CREATE [OR REPLACE] [] VIEW [database.] [()]
AS

CREATE VIEW `view_articles`
AS
SELECT
    a.id AS id,
    a.title AS title,
    a.content AS content,
    t.name AS tagname,
    u.firstname 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;
修改

ALTER [] VIEW [.] [()]
AS


ALTER VIEW `view_articles`
AS
SELECT
    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;

修改已经建立好的视图表,最简单的方法就是在phpMyAdmin导出视图表的SQL,然后修改开头的“CREATE”(后面的”ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER”等不用管,保留它)为”ALTER”,运行语句即可。

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!