Solved

Stored Procedures

Posted on 2009-03-29
5
235 Views
Last Modified: 2013-11-25
What is the importance of stored procedures?
Is it necessary to use stored procedures in every project? why?
0
Comment
Question by:Whing Dela Cruz
  • 2
  • 2
5 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 24011732
stored procedures provide 2 main advatages:
1) encapsulation - if you have some logic to perform in the database, the application don't know about this logic. The stored procedure provides an api, and you can later change the stored procedure as much as you want without changing the application at all (as long as the api dosn't change)
2) it has better performance - if you need to perform multiple statements, you only perform one call to the database, and all the work is done there, and you receive a response. this way you minimize the amount of database calls and network traffic that your application needs

it is not a must to use stored procedures in every application, but it is recommended
0
 

Author Comment

by:Whing Dela Cruz
ID: 24011746
Can  you give me example on how to do it? or any advice to start it?
Thanks!!
0
 
LVL 37

Accepted Solution

by:
momi_sabag earned 500 total points
ID: 24011749
you can find tones of example on the the internet
just google for
sql server stored procedures examples
calling sql server stored procedures from vb
0
 

Author Closing Comment

by:Whing Dela Cruz
ID: 31563989
Okey thanks!
More power to you!
0
 
LVL 26

Expert Comment

by:Chris Luttrell
ID: 24011758
This is just an example to get customer info from the customer table by passing in the id.  They can be much more complex if needed.  As for how to start, just take the queries you have and call and put the conditions that change like CustId as the parameters up top and the variable into the query.
-- Create the SP
CREATE Procedure spCustomerInfo
@CustId int
as
Select CompanyName, LastName, FirstName, OpenBalance, CreditLimit
From Customer
Where CustId = @CustId
GO
 
-- Use it
exec spCustomerInfo @CustID = 100
-- or this will work also
exec spCustomerInfo 100

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

829 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