Why Use Views

You've already seen one use for views. Here are some other common uses:

  • To reuse SQL statements.

  • To simplify complex SQL operations. After the query is written, it can be reused easily, without having to know the details of the underlying query itself.

  • To expose parts of a table instead of complete tables.

  • To secure data. Users can be given access to specific subsets of tables instead of to entire tables.

  • To change data formatting and representation. Views can return data formatted and presented differently from their underlying tables.

For the most part, after views are created, they can be used in the same way as tables. You can perform SELECT operations, filter and sort data, join views to other views or tables, and possibly even add and update data. (There are some restrictions on this last item. More on that in a moment.)

The important thing to remember is views are just that, views into data stored elsewhere. Views contain no data themselves, so the data they return is retrieved from other tables. When data is added or changed in those tables, the views will return that changed data.

你可能感兴趣的:(view)