如何最小化存储过程的处理时间 [英] how to minimize the process time of stored procedure

查看:126
本文介绍了如何最小化存储过程的处理时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请某人告诉我如何最小化存储过程的处理时间或执行时间。

请帮我

Pls some one tell that how to minimize the process time or execution time of stored procedure.
pls help me

推荐答案

你好,



您的存储过程中必须有一些查询执行一些插入,选择,更新等。

检查战略列(列)某些索引是否涉及某些索引。

如果没有,则创建涉及这些列的索引,这将有助于最小化ur sp的执行时间。

接下来,您可以通过点击Ctrl + M查看您的查询的实际执行计划,然后您可以分析您需要注意的位置。

Google for some SQL调优的东西,你也可以从他们那里获得帮助。

另外,如果你的sp有更多的临时表,试着用一些组合和东西来消除它们。

它也会有所帮助。

也看看下面的链接。



SQL Tuning Tutorial - 了解数据库执行计划(1) [ ^ ]



快乐编码.. :)



问候

anurag
Hi,

There must be some queries in your stored procedure performing some inserts,selects,updates etc.
Check whether the strategic columns(columns upon which the above operations are taking place) are involved in some indexes or not.
If not, then create indexes involving these columns, it will help in minimizing the execution time of ur sp.
Next you can view the actual execution plan of ur queries in ur sp by clicking ''Ctrl+M'', and then u can analyse where you need attention.
Google for some SQL tuning stuffs, and you can get help from them too.
Also, if ur sp has manier temporary tables, try to eliminate them by some combination and stuffs.
It too will help.
have a look at the below link too.

SQL Tuning Tutorial - Understanding a Database Execution Plan (1)[^]

Happy coding..:)

regards
anurag


使用查询分析器& SQL Profiler 的SQL Server查找查询成本和性能。看看瓶颈在哪里,并尝试微调它。



参考:

查询分析器,找到位置:

- 程序> Microsoft SQL Server 2008 R2>用于查询分析器的SQL Server Management Studio。

- 节目> Microsoft SQL Server 2008 R2>表演工具>用于探查器的SQL Server Profiler。



如果需要,在DB中定义视图并使用它:

MSDN:创建视图 [ ^ ]

SQL Server 2005中的视图概述 [ ^ ]
Use Query analyzer & SQL Profiler of SQL Server to find the query cost and performance. See where the bottle neck is and try to fine tune it.

References:
Query Analyzer, find at location:
- Programs > Microsoft SQL Server 2008 R2 > SQL Server Management Studio for Query Analyzer.
- Programs > Microsoft SQL Server 2008 R2 > Performance Tools > SQL Server Profiler for profiler.

If needed, define Views in DB and use it:
MSDN: Create VIEW[^]
Overview of Views in SQL Server 2005[^]


嗨亲爱的,



我列出了生成存储过程时要记住的一些要点。



1.使用模式名称和对象名称(Sql可以轻松搜索对象)并快速直接)

2.包括SET NOCOUNT ON语句(避免其他消息,如2行有效)

3.使用If exists(SELECT top 1)代替(SELECT *)(不包括l数据的大小)

4.尽可能避免使用游标

5.不要在存储过程名称中使用sp_前缀(因为System SP)模式)

6.使用sp_executesql存储过程而不是EXECUTE语句

7.使用Try-Catch处理错误

8.交易应该尽可能小。
Hi Dear,

I am listing some points to be keep in mind when generate Stored Procedure.

1. Use schema name with object name (Sql can search your object easily and fast and directly)
2. Include SET NOCOUNT ON statement (avoid additional messages like "2 rows effected")
3. Use If exists (SELECT top 1) instead of (SELECT *) (short of length of data)
4. Try to avoid using cursors if possible
5. Do not use the prefix of "sp_" in the stored procedure name(Because of System SP Pattern)
6. Use the sp_executesql stored procedure instead of the EXECUTE statement
7. Use Try-Catch for handling errors
8. Transaction should be as small as possible.


这篇关于如何最小化存储过程的处理时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆