MS SQL存储过程优化

时间:2014-10-28 13:29:00

标签: sql stored-procedures optimization

我附上了查询结果。我怎样才能优化这个sp?我还需要优化吗?我可以在0.2或更多的情况下获得结果。

Client Execution Time   18:18:18        18:18:08        18:17:49        18:17:24        18:13:18        
Query Profile Statistics                                            
  Number of INSERT, DELETE and UPDATE statements    281     281     281     50      0       178.6000
  Rows affected by INSERT, DELETE, or UPDATE statements 235     235     235     44      0       149.8000
  Number of SELECT statements   4870        4870        4870        741     13      3072.8000
  Rows returned by SELECT statements    3653        3653        3653        598     37      2318.8000
  Number of transactions    281     281     281     50      0       178.6000
Network Statistics                                          
  Number of server roundtrips   1       1       1       3       3       1.8000
  TDS packets sent from client  1       1       1       3       3       1.8000
  TDS packets received from server  119     110     90      898     78      259.0000
  Bytes sent from client    138     138     138     284     288     197.2000
  Bytes received from server    327491      327491      327491      2861601     197860      808386.8000
Time Statistics                                         
  Client processing time    2755        3793        2364        908     332     2030.4000
  Total execution time  3225        4294        2825        2095        1375        2762.8000
  Wait time on server replies   470     501     461     1187        1043        732.4000

1 个答案:

答案 0 :(得分:0)

您可以查看以下几个选项:

1.SQL合并 SQL Merge可用于在单个语句中执行插入,更新和删除。 http://technet.microsoft.com/en-us/library/bb510625.aspx http://blog.sqlauthority.com/2008/08/28/sql-server-2008-introduction-to-merge-statement-one-statement-for-insert-update-delete/

2.输出条款 在执行插入或更新时,SQL输出子句可用于从“inserted”和“deleted”(新值和旧值)表中返回任何值。 http://msdn.microsoft.com/en-us/library/ms177564(v=sql.90).aspx