Alex Rivera | Logout

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

Asked 2009-10-21T21:47:34.107
50

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 be a little more specific.
I wanted to know the performance difference for a particular query in a View, versus the exact same query inside a stored procedure. (I still appreciate all of the answers that point out their different capabilities)

Edit
Report

1 Answer

3

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.

answered 2009-10-24T22:14:15.200

Your Answer