Basics of Stored Procedures

Discussion in 'SQL Server' started by Safari, Apr 8, 2009.

  1. Safari

    Safari New Member

    Joined:
    Oct 16, 2007
    Messages:
    183
    Likes Received:
    17
    Trophy Points:
    0
    SQL Server implements Client/Server technology.A number of client send queries to the Central Server.The server after receiving the query request,parses it for syntax errors and process the request.Since the query passes from the client to the server through the network it adds to network traffic.Hence an increase in the number of queries from the clients leads to network congestion and load on the server.A stored procedure can solve this problem.

    It is a collection or batch of T-SQL statements and control-of-flow language that is stored under one name and executed as a single unit.It helps in improving the performance of the query.A stored procedure is a precompiled object and is readily available for the various applications to execute.

    Features of stored procedures are:-

    1. Improved Performance
    2. Reduction in network congestion
    3. Enhanced accuracy
    4. Better consistency
    5. Better security mechanism

    Types of procedures

    1. User-Defined stored procedures :- They are created and stored in the current database.
    2. System stored procedures :- They have names prefixed with sp_. These primarily support various administrative tasks that help manage the SQL SERVER.System stored procedures are stored in the system database and are accessible to the users of all the database.
    3. Temporary stored procedures:- It has names prefixed with the #symbol .They are stored in tempdb database and are automatically dropped when the connection terminates.
    4. Remote stored procedures :- They are the procedures that are created and stored in databases on remote servers. These can be accessed from various servers,provided user has appropriate permissions.
    5. Extended stored procedures:- These are dlls that are executed outside the SQL Server environment.
    Syntax to create procedure is
    Code:
    CREATE PROCEDURE proc_name
    AS
    BEGIN
    sql_statement1
    sql_statement2
    END
    
    Where proc_name specifies the name of the stored procedure.

    Syntax to execute procedure is

    Code:
    EXECUTE proc_name
    Syntax to drop procedure is

    Code:
    DROP PROCEDURE proc_name
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
  3. alourd

    alourd New Member

    Joined:
    Jun 4, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Thanks a lot for your useful article
     
  4. technica

    technica New Member

    Joined:
    Dec 15, 2007
    Messages:
    107
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.technicaltalk.net
    good article. But you haven't included about passing arguments to stored procedures. Inclusion of this will complete the article. Thanks for sharing.
     
  5. lingoway

    lingoway New Member

    Joined:
    Aug 10, 2010
    Messages:
    24
    Likes Received:
    4
    Trophy Points:
    0
    thanks for sharing
     
  6. rameshb

    rameshb New Member

    Joined:
    Dec 10, 2010
    Messages:
    35
    Likes Received:
    1
    Trophy Points:
    0
    You just provided an example for stored procedure would you please provide me with a real life example for procedures . I badly need it
     
  7. kumarmannu

    kumarmannu Banned

    Joined:
    Feb 2, 2011
    Messages:
    51
    Likes Received:
    0
    Trophy Points:
    0
    thanks tell how we will create it and and connect with the server please.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice