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

  • SEARCH
  • Home
  • 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 798517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:59:03+00:00 2026-05-14T22:59:03+00:00

Im searching for a very high performant possibility to insert data into a MS

  • 0

Im searching for a very high performant possibility to insert data into a MS SQL database.
The data is a (relatively big) construct of objects with relations. For security reasons i want to use stored procedures instead of direct table access.

Lets say i have a structure like this:

  • Document
    • MetaData
      • User
      • Device
    • Content
      • ContentItem[0]
        • SubItem[0]
        • SubItem[1]
        • SubItem[2]
      • ContentItem[1]
        • …
      • ContentItem[2]
        • …

Right now I think of creating one big query, doing somehting like this (Just pseudo-code):

EXEC @DeviceID = CreateDevice ...;
EXEC @UserID = CreateUser ...;
EXEC @DocID = CreateDocument @DeviceID, @UserID, ...;

EXEC @ItemID = CreateItem @DocID, ...
EXEC CreateSubItem @ItemID, ...
EXEC CreateSubItem @ItemID, ...
EXEC CreateSubItem @ItemID, ...
...

But is this the best solution for performance? If not, what would be better?
Split it into more querys? Give all Data to one big stored procedure to reduce size of query? Any other performance clue?

I also thought of giving multiple items to one stored procedure, but i dont think its possible to give a non static amount of items to a stored procedure.
Since ‘INSERT INTO A VALUES (B,C),(C,D),(E,F) is more performant than 3 single inserts i thought i could get some performance here.

Thanks for any hints,
Marks

  • 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-14T22:59:04+00:00Added an answer on May 14, 2026 at 10:59 pm

    One stored procedure so far as possible:

    INSERT INTO MyTable(field1,field2)
    SELECT "firstValue", "secondValue"
    UNION ALL
    SELECT "anotherFirstValue", "anotherSecondValue"
    UNION ALL
    

    If you aren’t sure about how many items you’re inserting you can construct the SQL query witin the sproc and then execute it. Here’s a procedure I wrote to take a CSV list of groups and add their relationship to a user entity:

    ALTER PROCEDURE [dbo].[UpdateUserADGroups]
    @username varchar(100),
    @groups varchar(5000)
    AS
    BEGIN
    DECLARE @pos int,
    @previous_pos int,
    @value varchar(50),
    @sql varchar(8000)
    
    SET @pos = 1
    SET @previous_pos = 0
    SET @sql = 'INSERT INTO UserADGroups(UserID, RoleName)'
    
    DECLARE @userID int
    SET @userID = (SELECT TOP 1 UserID FROM Users WHERE Username = @username) 
    
    WHILE @pos > 0
    BEGIN
     SET @pos = CHARINDEX(',',@groups,@previous_pos+1)
     IF @pos > 0
     BEGIN
     SET @value = SUBSTRING(@groups,@previous_pos+1,@pos-@previous_pos-1)
     SET @sql = @sql + 'SELECT ' + cast(@userID as char(5)) + ',''' + @value + ''' UNION ALL '
    SET @previous_pos = @pos
    END
    END
    
    IF @previous_pos < LEN(@groups)
    BEGIN
      SET @value = SUBSTRING(@groups,@previous_pos+1,LEN(@groups))
      SET @sql = @sql + 'SELECT ' + cast(@userID as char(5)) + ',''' + @value + ''''
    END
    print @sql
    exec (@sql)
    
    END
    

    This is far faster than individual INSERTS.

    Also, make sure you just a single clustered index on the primary key, more indexes will slow the INSERT down as they will need to update.

    However, the more complex your dataset is, the less likely it is that you’ll be able to do the above so you will simply have to make logical compromises. I actually end up calling the above routine around 8000 times.

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

Sidebar

Related Questions

I'm looking for a binary data structure (tree, list) that enables very fast searching.
Ive recently started using CodeIgniter as I was searching for a very lightweight framework
This is quite possibly a very stupid question but I've tried searching for and
so I have been searching your website and im still very unclear on how
Maybe I am searching with the wrong keywords or this is a very basic
Here's a very simple, probably duplicate (sorry - I have tried searching) shell scripting
I'm searching for any PEP 3124 implemenation or development process. I'm not very familliar
Maybe, it's very simple question but I couldn't get the answer. I've been searching
What I need is very simple but, searching the web, I didn't find any
i am very new in jquery. so i was searching google for jquery callback

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.