数据库
首页 > 数据库> > Top 3 Tips You Need to Know to Write Faster SQL Views

Top 3 Tips You Need to Know to Write Faster SQL Views

作者:互联网

Top 3 Tips You Need to Know to Write Faster SQL Views

Friend or foe? SQL Server views have been a subject of heated debates when I was in my first year using SQL Server. They said it was bad because it was slow. But how about today?

Are you on the same boat as I was many years ago? Then, join me on this journey to unravel the real deal about SQL views so that you can write them the fastest possible.

SQL views are virtual tables. The records in a view are the result of a query inside it. Whenever the base tables used in the view get updated, it updates the view too. You can also INSERT, UPDATE, and DELETE records in a view as a table in some cases. Though I haven’t tried this myself.

Similarly to a table, you can CREATE, ALTER, or DROP a view. You can even create an index, with some restrictions.

Note that I used SQL Server 2019 in the sample codes.

 

1. Know the Proper and Improper Use of SQL Views

First, the basics.

What are SQL views for?

It is crucial. If you use it as a hammer to a screwdriver, forget about faster SQL views. First, let’s recall the proper use:

How NOT to use SQL Server views?

Improper use of views, if permitted, will obscure the real reason why you create views. As you will see later, the real benefits outweigh the perceived benefits of improper usage.

 

标签:use,Faster,views,Top,Views,Server,SQL,table,view
来源: https://www.cnblogs.com/chucklu/p/16385369.html