Solved

View & Procedure - SQL Server

Posted on 2013-01-06
3
315 Views
Last Modified: 2013-01-06
Hello All,

I cant help but ask this question to all SQL Gurus here.

Recently I created a VBA application that calls a complex set of sql statements to show a data set in a certain way.
In order to accomplish the above, I tried doing it in two different ways...

1)I created a stored procedure to do the above
2)I also created a View to do the above.

I was tracking the seconds in the VBA application in terms of the time it takes to complete the command.

I found some real interesting info:

When VBA called the view from SQL Server, it took near to 1 minute
when VBA called the stored procedure from SQL Server it took 30 seconds

Why is this amazing difference ?

Is the stored procedure is better off than view in certain cases?
What are the advantages of using StoredProcedure ? Why would you want one, performance wise? like whats the real 'physics' behind it, that makes it preferable...if you get what I am saying..

Thanks
R
0
Comment
Question by:Rayne
3 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 300 total points
ID: 38749173
Why is this amazing difference ?
A well-coded Stored Procedure will always outperform a VIEW.  This is especially true after the plan is cached.  In other words, you execute it a second time and the Stored Procedure plan is still in memory.

Is the stored procedure is better off than view in certain cases?
See above.

What are the advantages of using StoredProcedure ?
Performance and security.
0
 
LVL 8

Assisted Solution

by:Crashman
Crashman earned 200 total points
ID: 38749215
Take a look,


SQL SERVER – The Limitations of the Views – Eleven and more…

SQL Server Journey with SQL Authority
0
 

Author Closing Comment

by:Rayne
ID: 38749451
Awesome Guys, hats off to you!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question