Top 3 Tips You Need to Know to Write Faster SQL Views
2022/6/18 2:20:27
本文主要是介绍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:
- 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.
这篇关于Top 3 Tips You Need to Know to Write Faster SQL Views的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-19永别了,微服务架构!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?