Search code examples
sqlsql-server-2008stored-procedurescomparisonview

Stored Procedures Vs. Views


I have used both but what I am not clear is when I should prefer one over the other. I mean I know stored procedure can take in parameters...but really we can still perform the same thing using Views too right ?

So considering performance and other aspects when and why should I prefer one over the other ?


Solution

  • Well, I'd use stored proc for encapsulation of code and control permissions better.

    A view is not really encapsulation: it's a macro that expands. If you start joining views pretty soon you'll have some horrendous queries. Yes they can be JOINed but they shouldn't..

    Saying that, views are a tool that have their place (indexed views for example) like stored procs.