Is it okay to have a lot of database views?

后端 未结 4 2029
忘掉有多难
忘掉有多难 2021-02-20 18:51

I infrequently (monthly/quarterly) generate hundreds of Crystal Reports reports using Microsoft SQL Server 2005 database views. Are those views wasting CPU cycles and RAM durin

4条回答
  •  情话喂你
    2021-02-20 18:51

    A view is a query that you run often with preset parameters. If you know you will be looking at the same data all the time you can create a view for ease of use and for data binding.

    That being said, when you select from a view the view defining query is run along with the query you are running.

    For example, if vwCustomersWhoHavePaid is:

    Select * from customers where paid = 1
    

    and the query you are running returns the customers who have paid after August first is formatted like this:

    Select * from vwCustomersWhoHavePaid where datepaid > '08/01/08'
    

    The query you are actually running is:

    Select * from (Select * from customers where paid = 1) where datepaid > '08/01/08'
    

    This is something you should keep in mind when creating views, they are a way of storing data that you look at often. It's just a way of organizing data so it's easier to access.

提交回复
热议问题