Solved

View & Procedure - SQL Server

Posted on 2013-01-06
3
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

695 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