Why is the database view used?

Uses "view" in the correct db design method, or should we handle it from the code side? What are the advantages or disadvantages?

+6
database-design view database-schema advantage-database-server
source share
3 answers

I see several reasons for using views:

  • Provide a simpler interface: just request a view, not dozens of tables, do joins and that's it
  • Provide an interface that does not change (or less frequently):
    • Even if you change the structure of the tables, you can change your view so that it still returns the same.
    • This means that no changes are required in the application code: it will still work, since it uses a view and does not directly access tables
  • Provide only an interface for some table fields
    • No need for users to see some data that they will not use.
    • Or to access some data they should not use
  • With some database engines (I think MS SQL Server supports this), some types of views may have indexes
    • What's good for presentations: if you have a complex query, save it as a view and define the necessary indexes in that view
+13
source share

Two typical scenarios for presentation in our case:

  • Some columns in the table contain sensitive data that only some people should see. You can create a view that excludes these columns and uses this view for most users.
  • You combine two or more tables into a denormalized view, which is practical for reporting purposes, but does not make sense as a table for storing in a database.

Hope this helps.

+3
source share

It depends. I use sometmies, but not so often. They are VERY useful for advanced decoded data representations used by the end user (tools), for example, for reports. Thus, you can provide the end user with a simplified version of frequently requested information that hides some technical details.

+2
source share

All Articles