Is it okay to have a lot of database views?

后端 未结 4 2031
忘掉有多难
忘掉有多难 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:59

    You ask: What's going on behind the scenes?

    A view is a bunch of SQL text. When a query uses a view, SQL Server places that SQL text into the query. This happens BEFORE optimization. The result is the optimizer can consider the combined code instead of two separate pieces of code for the best execution plan.

    You should look at the execution plans of your queries! There is so much to learn there.

    SQL Server also has a concept of a clustered view. A clustered view is a system maintained result set (each insert/update/delete on the underlying tables can cause insert/update/deletes on the clustered view's data). It is a common mistake to think that views operate in the way that clustered views operate.

提交回复
热议问题