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

后端 未结 11 700
星月不相逢
星月不相逢 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:30

    Unfortunately, they're not the same type of beast.

    A stored procedure is a set of T-SQL statements, and CAN return data. It can perform all kinds of logic, and doesn't necessarily return data in a resultset.

    A view is a representation of data. It's mostly used as an abstraction of one or more tables with underlying joins. It's always a resultset of zero, one or many rows.

    I suspect your question is more along the lines of:

    Which is faster: SELECTing from a view, or the equivalent SELECT statement in a stored procedure, given the same base tables performing the joins with the same where clauses?

提交回复
热议问题