Solved

View & Procedure - SQL Server

Posted on 2013-01-06
3
310 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ms sql stored procedure 22 77
The duplicate key value is (<NULL>) 14 44
SQL Help - 12 36
Log Backup 2 12
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now