SQL-Server Performance: What is faster, a stored procedure or a view?

后端 未结 11 702
星月不相逢
星月不相逢 2020-12-04 23:53

What is faster in SQL Server 2005/2008, a Stored Procedure or a View?

EDIT: As many of you pointed out, I am being too vague. Let me attempt to

11条回答
  •  我在风中等你
    2020-12-05 00:31

    This isn't really an answerable question in that an answer will hold true in all cases. However, as a general answer for an SQL Server specific implementaion...

    In general, a Stored Procedure stands a good chance of being faster than a direct SQL statement because the server does all sorts of optimizations when a stored procedure is saves and executed the first time.

    A view is essentially a saved SQL statement.

    Therefore, I would say that in general, a stored procedure will be likely to be faster than a view IF the SQL statement for each is the same, and IF the SQL statement can benefit from optimizations. Otherwise, in general, they would be similar in performance.

    Reference these links documentation supporting my answer.

    http://www.sql-server-performance.com/tips/stored_procedures_p1.aspx

    http://msdn.microsoft.com/en-us/library/ms998577.aspx

    Also, if you're looking for all the ways to optimize performance on SQL Server, the second link above is a good place to start.

提交回复
热议问题