spacer
Yehuda Shiran October 1, 2002
Advantages of Stored Procedures
Tips: October 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

IBuySpy Store uses stored procedure extensively. These are SQL scripts that are stored permanently in the MSSQL database, and are called from within the JScript .NET code. In fact, all interactions with the database are accomplished via stored procedures. There are several advantages to using stored procedures instead of writing SQL queries in the JScript .NET code. Performance and ease of maintenance are two obvious reasons to use stored procedures. To view IBuySpy's stored procedures, you need to open MSSQL Enterprise, and look under the StoreDOCJS database for the Stored Procedures entry. You will find 23 stored procedures. Double click one of the stored procedures to view its content. Here is the CustomerAlsoBought stored procedure:

  CREATE Procedure CustomerAlsoBought
  (
      @ProductID int
  )
  As

  /* We want to take the top 5 products contained in
      the orders where someone has purchased the given Product */
  SELECT  TOP 5 
      OrderDetails.ProductID,
      Products.ModelName,
      SUM(OrderDetails.Quantity) as TotalNum

  FROM    
      OrderDetails
    INNER JOIN Products ON OrderDetails.ProductID = Products.ProductID

  WHERE   OrderID IN 
  (
      /* This inner query should retrieve all orders that have contained the productID */
      SELECT DISTINCT OrderID 
      FROM OrderDetails
      WHERE ProductID = @ProductID
  )
  AND OrderDetails.ProductID != @ProductID 

  GROUP BY OrderDetails.ProductID, Products.ModelName 

  ORDER BY TotalNum DESC

  GO

People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business