What are the differences between a TABLE and a VIEW in a MySQL database?
I'm joining a number of tables and want to create some tables or views that are easier to query against to do quick analysis of our data. What are the implications of creating a new table or new view with the combined data.
开发者_StackOverflowCurrently the tables I'm joining are static, but this code may be moved to our live tables in the future.
This is a slight oversimplification, but a view is basically a saved query on a table returning a result (in rows and columns), which you can then query as if it were its own table.
As of MySQL 5.0, views weren't all that great because it executed the underlying query every time it was used, so there really wasn't much point to them (although they could be useful for code reuse). That may have changed since 5.0, though.
A Table stores the data
A View is a stored procedure like select * from table
saved in the database for later use
you could have a view joining two tables and then select from that view without a join clause but get a joined result
Be careful with views, as they don't necessarily use the indexes correctly in the underlying tables!
See this article for more information
http://www.mysqlperformanceblog.com/2007/08/12/mysql-view-as-performance-troublemaker/
In addition to Rob's explanation:
You can grant privileges not only on tables, but also on views. With this you can give access only to a compiled subset of a databases data.
精彩评论