ASP.NET
  Home arrow ASP.NET arrow Developing T-SQL Stored Procedures to Deal...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Developing T-SQL Stored Procedures to Deal with Lookup Tables
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 11
    2006-09-26

    Table of Contents:
  • Developing T-SQL Stored Procedures to Deal with Lookup Tables
  • How to update/delete a row in a table using a T-SQL stored procedure
  • How to retrieve one or all rows in a table using a T-SQL stored procedure
  • How to retrieve a set of rows in a particular order using a T-SQL stored procedure
  • How to retrieve a set of rows page by page using a T-SQL stored procedure

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Developing T-SQL Stored Procedures to Deal with Lookup Tables


    (Page 1 of 5 )

    In this article, I shall go through a set of Transact-SQL stored procedures which are very frequently used for CRUD operations on lookup tables. My upcoming articles will deal with DAL (Data Access Layers) in .NET based on these stored procedures.

    As I wanted to demonstrate stored procedures which do not modify existing data in AdventureWorks/Northwind, I created a table “emp” with the following columns and data types:

    • Empno (int)
    • Ename (nvarchar(50))
    • Sal (float)
    • Deptno (int)

    I pushed the following sample rows into that table:

    How to insert a row into a table using a T-SQL stored procedure

    The following is the stored procedure which deals with inserting a particular row into a table. 

    CREATEPROCEDURE [dbo].[p_emp_Insert]
          @empno int,
          @ename varchar(50),
          @sal float,
          @deptno int
    AS
    INSERTINTO [dbo].[emp] (
          [empno],
          [ename],
          [sal],
          [deptno]
    )VALUES (
          @empno,
          @ename,
          @sal,
          @deptno
    )
    RETURN

    The above is a stored procedure named “p_emp_insert” which accepts four parameters (according to the columns available in the table).  Once all the parameters are passed in, it executes an INSERT statement to insert those values in the form of a row.

    To test the above stored procedure, you can issue the following statement in Query Analyzer or SQL Server Management Studio.

    executedbo.p_emp_Insert 2001, 'zzz', 4500, 20

    The next section will give the code for updating a row.

    More ASP.NET Articles
    More By Jagadish Chaterjee


       · Hello guys! this is a simple article on developing most frequently used T-SQL stored...
     

    ASP.NET ARTICLES

    - Disadvantages of the ASP.NET MVC Framework
    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT