Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

SQL Server 2000:Creating and Using Stored Procedures

By Exforsys | on March 12, 2005 |
SQL Server
This tutorial series covers the basic concepts of Stored Procedures in SQL Server and hot create and execute a simple stored procedure.

Using Stored Procedures

Some of the most important concerns to a database user are speed and efficiency. Faster data retrieval provides applications to responds and behaves quickly. SQL Server provides “Stored Procedures” for faster and quick data access.


Stored Procedures is a query that is stored in a database on SQL Server rather than being stored in the front-end code on users machine. You may think that storing queries in the form of Stored Procedures will be an overhead itself??? But its not the case here. Stored Procedures are of three types.

  1. User-defined Stored Procedures
  2. System Stored Procedures
  3. Extended Stored Procedures

We will mainly focus on User-defined stored procedures, although we will also take a look on System and Extended Stored Procedures.


Stored Procedures provide two major benefits over ad-hoc queries.

  1. Better Performance
  2. Database Management.

Better Performance:


As Stored Procedures resides on the server, they remarkably enhance its performance and release the network traffic from congestion.

Consider a database “TestDB” with a table, named “Customer”. It has three columns FirstName , LastName and Location. We are going to execute our queries on this table.

We are writing an ad-hoc query, which selects the First Name and Last Name of all customers from “Customer” table, which lives in “New York”. The query looks


SELECT FirstName , LastName
FROM Customer
WHERE Location = ‘New York’
ORDER BY FirstName

Although, the query doesn’t seems to be large, imagine having 1000 users which are executing this query many times in a day, sending a large traffic over the network and causing congestion (as the query resides on client machine, which send it to server for execution).

Every time the whole query sends to the server (in text format) and receiving the result. Instead of doing this, we should put our query on the server (in the form of Stored Procedure) and just call to execute it and return the recordset. The only could then send over the network (from the client machine) is


EXEC stored_procedure_name


Another advantage of Stored procedures is that they are precompiled. Whenever you send an ad-hoc query to SQL Server, it reads the query, looks at such things as JOINS, WHERE clauses etc. Then it creates the execution plan in memory. Where as Stored Procedures are compiled one time and they just need to be executed. The have gone through all the above process and have a plan waiting in memory, so they execute faster.

Database Management:

Next advantage of stored procedures is they make database management process easier. Suppose you want to change an ad-hoc query and the query resides on the client machine then what will you do??? You will change the query in all the client machines where as in Stored Procedures you just make the changes on the server (as they reside on the database server) and that’s all.

Remember that using stored procedures are not always suitable. If your query doesn’t not run frequently then you can use ad-hoc queries.

Creating Basic Stored Procedure:

We are going to write the above ad-hoc query (which we have gone through above) in the form of Stored Procedure. Steps are

  • Open Enterprise Manager, expand your database server, then your selected database (on which you will write Stored Procedure)
  • Under “TestDB” database, select “Stored Procedure”
  • From the action menu, select “New Stored Procedure”
  • A pop-up window comes. Write the code in it.

CREATE PROCEDURE Show_Customer AS
SELECT FirstName, LastName FROM Customer
WHERE Location=’New York’
ORDER BY FirstName

  • Click the “Check Syntax” button to check whether the syntax is correct or not.
  • Press the “Apply” or “Ok” button.

To execute the procedure,

  • Open Query Analyzer
  • Enter the following code in it

    USE TestDB
    EXEC Show_Customer
  • Click the Execute button

Now, We have understood how to create and execute Stored Procedures. But here in our Stored Procedure, there is a problem i.e. if we want to view customers having different locations then it will not help us as it can return only customers live in New York. Here comes Stored Procedures with Input Parameters.

« « Using Rich Server Controls with C#
SQL Server 2000: Creating Stored Procedure with Input and Output Parameters » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 394 Followers
  • Popular
  • Recent
  • SQL Server 2000: Creating Stored Procedure with Input and Output Parameters

    March 12, 2005 - 0 Comment
  • SQL Server 2000 Training Details

    March 11, 2005 - 0 Comment
  • SQL Server 2000: Securing Your Stored Procedure

    March 13, 2005 - 0 Comment
  • SQL Server 2000: Using System and Extended Stored Procedures

    March 13, 2005 - 0 Comment
  • SQL Server 2000: Using Views in SQL Server

    March 17, 2005 - 0 Comment
  • SQL Server 2000: Using Views in SQL Server

    March 17, 2005 - 0 Comment
  • SQL Server 2000: Using System and Extended Stored Procedures

    March 13, 2005 - 0 Comment
  • SQL Server 2000: Securing Your Stored Procedure

    March 13, 2005 - 0 Comment
  • SQL Server 2000: Creating Stored Procedure with Input and Output Parameters

    March 12, 2005 - 0 Comment
  • SQL Server 2000 Training Details

    March 11, 2005 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • SQL Server 2000: Using Views in SQL Server
  • SQL Server 2000: Using System and Extended Stored Procedures
  • SQL Server 2000: Securing Your Stored Procedure
  • SQL Server 2000: Creating Stored Procedure with Input and Output Parameters
  • SQL Server 2000 Training Details

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT