Why do you create a View in a database?

前端 未结 25 1974
一个人的身影
一个人的身影 2020-11-28 17:10

When and Why does some one decide that they need to create a View in their database? Why not just run a normal stored procedure or select?

25条回答
  •  感情败类
    2020-11-28 17:57

    I usually create views to de-normalize and/or aggregate data frequently used for reporting purposes.

    EDIT

    By way of elaboration, if I were to have a database in which some of the entities were person, company, role, owner type, order, order detail, address and phone, where the person table stored both employees and contacts and the address and phone tables stored phone numbers for both persons and companies, and the development team were tasked with generating reports (or making reporting data accessible to non-developers) such as sales by employee, or sales by customer, or sales by region, sales by month, customers by state, etc I would create a set of views that de-normalized the relationships between the database entities so that a more integrated view (no pun intended) of the real world entities was available. Some of the benefits could include:

    1. Reducing redundancy in writing queries
    2. Establishing a standard for relating entities
    3. Providing opportunities to evaluate and maximize performance for complex calculations and joins (e.g. indexing on Schemabound views in MSSQL)
    4. Making data more accessible and intuitive to team members and non-developers.

提交回复
热议问题