Databases Reference
In-Depth Information
Views
MySQL 5.0 introduced support for named, updatable views. A view is a derived
table—consider it as a virtual table—whose definition is stored in the database. A
SELECT statement done on one or more tables (or even on views) is stored as a view
and can itself be queried. Views can be used to:
Limit the visibility of columns (do not show the salary)
Limit the visibility of rows (do not show data for specific world regions)
Hide a changed table structure (so that legacy applications can continue
to work)
As a view has itself some permissions attached to it, it is easier to GRANT permissions
on the view as a whole, rather than defining cumbersome column-specific privileges
on the underlying tables.
To activate views support on a server after an upgrade from a pre-5.0 version,
the administrator has to execute the mysql_fix_privileges_tables script, as
described in the MySQL manual.
Each user must have the appropriate SHOW_VIEW or CREATE_VIEW
privilege to be able to see or manipulate views. These privileges exist at
the global (server), database and table levels.
phpMyAdmin supports two ways of creating a view; we'll explain first the manual
method, then go on with a more automatic way.
Manually Creating a View
To manually create a view, we use the query box to enter the appropriate statement.
Let's input the following lines and click Go :
CREATE VIEW book_author AS
SELECT book.isbn, book.title, author.name FROM book
LEFT JOIN author ON author.id = book.author_id
Creating a view implies that the user has privileges on the tables
involved, or at least a privilege like SELECT or UPDATE on all the columns
mentioned in the view.
 
Search WWH ::




Custom Search