Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6612957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:09:35+00:00 2026-05-25T20:09:35+00:00

Greetings and thanks for reading! I was wondering what the best practice for encapsulating

  • 0

Greetings and thanks for reading!

I was wondering what the best practice for encapsulating stored procedure logic using a set-based SQL technique.

For example, I have a product entry application that I am developing. While attempting to limit code duplication, I created a stored procedure called AddItem which creates a new product in the product tables. The downside is that in order to utilize this procedure in a situation that requires adding a group of products, I am forced to use a cursor or WHILE loop to execute the procedure in a “FOR EACH” type of way. This is resulting in very poor performance on large sets of items.

Of course I could hard-code the INSERT statements into the calling procedure but that makes me feel icky because the whole point is to be able to change (in one place) the “add item” logic. So if a column changed I would have to remember to change all of the INSERT statements in all of the places that use it. I just figured there has to be a better way of doing this and any advice would be appreciated.

EDIT:
Quite right, I should provide a code example. Here is the contents of the AddItem procedure which is being executed on a MS SQL2005 database:

            ALTER PROCEDURE [dbo].[AddItem]
                @ProjectNumber  int,
                @ItemName       varchar(255),
                @SupplierID     int,
                @SKUType        int,
                @Store          varchar(3),
                @Category       varchar(4),
                @AddedBy        varchar(255),
                @ParentSKU      varchar(255) = NULL,
                @SetNumber      int = NULL,
                @NewItemNumber  int OUTPUT
            AS  
                SET NOCOUNT ON

                DECLARE @DiscontinuedStatus bit

                BEGIN TRY
                    BEGIN TRAN
                        SET @NewItemNumber = 0

                        INSERT INTO ProductEntry.dbo.Items
                        (ProjectNumber, SetNumber, SKUType, Store, Category, AddedBy, ParentSKU, EntryTime)
                        VALUES(@ProjectNumber, @SetNumber, @SKUType, @Store, @Category, @AddedBy, @ParentSKU, CURRENT_TIMESTAMP)

                        SET @NewItemNumber = SCOPE_IDENTITY()

                        IF @SKUType = 1
                        BEGIN
                            SET @DiscontinuedStatus = 1
                        END
                        ELSE
                        BEGIN
                            SET @DiscontinuedStatus = 0
                        END 

                        INSERT INTO ProductEntry.dbo.ItemInfo
                        (ItemNumber, ItemName, Discontinued)
                        VALUES (@NewItemNumber, @ItemName, @DiscontinuedStatus)

                        INSERT INTO ProductEntry.dbo.ItemSupplierInfo   
                        (ItemNumber, SupplierID)
                        VALUES(@NewItemNumber, @SupplierID)

                        INSERT INTO ProductEntry.dbo.ItemWebInfo
                        (ItemNumber)
                        VALUES(@NewItemNumber)

                        INSERT INTO ProductEntry.dbo.ItemTags
                        (ItemNumber)
                        VALUES (@NewItemNumber)
                    COMMIT TRAN
                END TRY
                BEGIN CATCH
                    ROLLBACK TRAN
                END CATCH

I have a need for a procedure that adds multiple items at a time (with numbers greater than 1000) and when using a cursor the performance is very bad. It takes over a minute to add a group of 800 products and it only gets worse from there.

EDIT:
To further clarify the solution, the application allows items that have a parent-child relationship. When adding a new parent item, the user selects from a list of options and a set of child items is generated based on the option set.

For example, a user could create a product called “Awesome Boot” with an option set of Colors=”Brown, Black”, Size=”10M, 11M, 12M”, ToeStyle=”SteelToe, SoftToe” – this would generate a set of 12 items. Obviously you can see how this could increase exponentially, considering that most boots have around 36 sizes, multiple colors and toe styles, as well as other options. This can result in a parent item with a large number of child items.

I guess one solution would be to combine all of the different item information into one “Items” table, eliminating the need for storing the same IDENTITY in multiple tables. I kind of like the convenience of splitting up the related data logically into different tables though. Maybe I’m trying to have my cake and eat it too!

Thanks! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:09:35+00:00Added an answer on May 25, 2026 at 8:09 pm

    This is just a stray comment – the two tables ItemWebInfo and ItemTags – unless those tables will eventually have multiple rows per entity, I think it would make a lot more sense (at least in most cases – there are always exceptions) if those columns were in the primary table. I also might suggest the same for the supplierInfo, unless an item can have more than one supplier the supplierID should just be a column in the primary table as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings! Working on a web based project were business rules and logic need to
Greetings, I'm confused as to the best approach to make when consuming REST based
Greetings Overflowers, Is there an SQL DBMS that allows me to create an indexed
Greetings! I have a Repeater control that's using an XmlDataSource control. <asp:FormView id=myFormView runat=server
Greetings, Trying to sort through the best way to provide access to my Entity
Greetings. I've been using vim for years, and I've recently started toying with XCode.
Hey guy's First of all thanks for reading this. I'm having trouble to find
Greetings, I'm using https://github.com/blueimp/jQuery-File-Upload (downloaded the version as of 5/21/2011) along with ASP.NET MVC3.
Greetings. For the life of me, I can't remember how to set the minimum
Greetings, I have a view based application project where I have created an NSObject

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.