Why do you create a View in a database?

2019-01-08 02:22发布

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?

24条回答
成全新的幸福
2楼-- · 2019-01-08 03:23

One curious thing about views are that they are seen by Microsoft Access as tables: when you attach a Microsoft Access front-end to an SQL database using ODBC, you see the tables and views in the list of available tables. So if you are preparing complicated reports in MS Access, you can let the SQL server do the joining and querying, and greatly simplify your life. Ditto for preparing a query in MS Excel.

查看更多
淡お忘
3楼-- · 2019-01-08 03:23

I only have 10 or so views in my production databases. I use several for columns I use all the time. One set I use come from 7 tables, some with outer joins and rather than rewrite that constantly I only have to call that view in a select and make one or 2 joins. To me it is just a time saver.

查看更多
啃猪蹄的小仙女
4楼-- · 2019-01-08 03:25

Views can be a godsend when when doing reporting on legacy databases. In particular, you can use sensical table names instead of cryptic 5 letter names (where 2 of those are a common prefix!), or column names full of abbreviations that I'm sure made sense at the time.

查看更多
劳资没心,怎么记你
5楼-- · 2019-01-08 03:26

Think of it as refactoring your database schema.

查看更多
放我归山
6楼-- · 2019-01-08 03:27

It can function as a good "middle man" between your ORM and your tables.

Example:

We had a Person table that we needed to change the structure on it so the column SomeColumn was going to be moved to another table and would have a one to many relationship to.

However, the majority of the system, with regards to the Person, still used the SomeColumn as a single thing, not many things. We used a view to bring all of the SomeColumns together and put it in the view, which worked out nicely.

This worked because the data layer had changed, but the business requirement hadn't fundamentally changed, so the business objects didn't need to change. If the business objects had to change I don't think this would have been a viable solution, but views definitely function as a good mid point.

查看更多
爷的心禁止访问
7楼-- · 2019-01-08 03:27

When I want to see a snapshot of a table(s), and/or view (in a read-only way)

查看更多
登录 后发表回答