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

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

    Stored procedures and views are different and have different purposes. I look at views as canned queries. I look at stored procedures as code modules.

    For example let's say you have a table called tblEmployees with these two columns (among others): DateOfBirth and MaleFemale.

    A view called viewEmployeesMale which filters out only male employees can be very useful. A view called viewEmployeesFemale is also very useful. Both of these views are self describing and very intuitive.

    Now, lets say you need to produce a list all male employees between the ages of 25 and 30. I would tend to create a stored procedure to produce this result. While it most certainly could be built as a view, in my opinion a stored procedure is better suited for dealing with this. Date manipulation especially where nulls are a factor can become very tricky.

提交回复
热议问题