MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:Baron Schwartz Date:February 9 2009 3:19pm
Subject:Re: MySQL View
View as plain text  
On Mon, Feb 9, 2009 at 9:41 AM, Steven Buehler <steve@stripped> wrote:
> Ok, I just saw a post about using view's in mysql.  I tried to look it up
> and found how to use it, but my question is: what is a view and why would
> you use it?  Is it like a temporary table?  Does it write a new database to
> the disk or use memory?

A view is a piece of SQL whose result can be queried like a table.  It
stores no data; the results are always generated as the query
executes.  In some cases it does use a temporary table to hold the
result and then query against it; in other cases it merges the
original query's SQL and the view's SQL together and then executes the
resulting query.

Why use it?  To abstract a complex bit of code away for simplicity.
To grant permissions in a certain way (you can grant access to the
view and deny access to the underlying table).

There's a lot of complexity to it though, in terms of how to use views
correctly and get good performance.  I think the manual goes over it
in good detail, and our book High Performance MySQL 2nd Edition has
probably the best exploration of it otherwise.


Baron Schwartz, Director of Consulting, Percona Inc.
Our Blog:
Our Services:
MySQL ViewSteven Buehler9 Feb
  • Re: MySQL ViewBaron Schwartz9 Feb
    • RE: MySQL ViewSteven Buehler9 Feb
      • RE: MySQL ViewMartin Gainty9 Feb
        • RE: MySQL ViewSteven Buehler9 Feb
          • Re: MySQL ViewClaudio Nanni9 Feb
            • RE: MySQL ViewSteven Buehler10 Feb
  • Re: MySQL ViewJochem van Dieten10 Feb
    • RE: MySQL ViewSteven Buehler10 Feb
      • Re: MySQL ViewJochem van Dieten10 Feb