ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

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

2022-06-17 13:03:09  阅读:182  来源: 互联网

标签:use Faster views Top Views Server SQL table view


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:

  • To focus, simplify, and customize the perception each user has of the database.
  • To allow the users access to the only information they need to see for security reasons.
  • To provide backward compatibility to an old table or an old schema to not break dependent apps. It is temporary until all the needed changes are complete.
  • To partition data coming from different servers. Therefore, they appear as if they are one table from one server or instance.

How NOT to use SQL Server views?

  • Reuse the view in another view that will be reused in yet, another view. In short, deeply nested views. The code reuse has a few drawbacks in this case.
  • Save on keystrokes. It relates to the first one, which reduces finger pressure and seems to accelerate coding.

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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有