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 8638679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:47:56+00:00 2026-06-12T10:47:56+00:00

We have built a C# .NET system that can be used to create data

  • 0

We have built a C# .NET system that can be used to create data warehouses. This system takes selected databases and run a script against these databases to create a combined database/warehouse.

Now, I have three databases to be compiled into a single database and I am copying two tables from each (table [XI] and table [XII] – which have a one to many relationship, but have no constraints set up at the time of the copy/INSERT INTO). The figures for the script to run and the relevant sizes for each table are below:

The executed script consists of 30 SQL queries.

  1. DatabaseA:

    Table [XI]  29,026 Rows (size 20,128Kb).
    Table [XII] 531,958 Rows (size 50,168Kb).
    Time taken for entire script: 1.51s.
    
  2. DatabaseB:

    Table [XI]  117,877 Rows (size 17,000Kb).
    Table [XII] 4,000,443 Rows (size 512,824Kb).
    Time taken for entire script: 2.04s.
    

These both run fine and fast. The next is almost exactly the same size as the first but takes 40x as long!

  1. DatabaseC:

    Table [XI]  29,543 Rows (size 20,880Kb).
    Table [XII] 538,302 Rows (size 68,000Kb).
    Time taken for entire script: 44.38s.
    

I cannot work out why this is taking so long. I have used SQL Server Profiler and the Performance Monitor, but I cannot nail-down the reason for this massive change in performance.

The query being used to do the update is dynamic and is shown at the bottom of this question – it is large due the explicit reference to the required columns. My question is; what could be causing this inordinate increase in execution time?

Any clues would be greatly appreciated.

SQL:

DECLARE @DbName NVARCHAR(128);
SET @DbName = (SELECT TOP 1 [DbName] 
               FROM [IPACostAdmin]..[TmpSpecialOptions]);
DECLARE @FilterSql NVARCHAR(MAX);
SET @FilterSql = (SELECT TOP 1 [AdditionalSQL] 
                  FROM [IPACostAdmin]..[TmpSpecialOptions]);
DECLARE @SQL NVARCHAR(MAX);
DECLARE @SQL1 NVARCHAR(MAX);
DECLARE @SQL2 NVARCHAR(MAX);
SET @SQL1 = 
    'INSERT INTO [' + @DbName + ']..[Episode] 
        ([Fields1], ..., [FieldN])'; 
SET @SQL2 = 
'SELECT 
     [Fields1], ..., [FieldN] 
FROM [B1A] ' + @FilterSql + ';'; 
SET @SQL = @SQL1 + @SQL2;
EXEC(@SQL);
GO

Note: I am splitting the dynamic SQL into @SQL1 and @SQL2 for clarity. Also note that I have not shown all columns due to space and the fact that it would largely be redundant.

Edit1.

1. The databases are on the same server.

2. The database files, including logs are in the same directory on the same drive.

3. There are no primary/foriegn keys or constraints set up on the source databases (DatabaseA/B/C) or the data warehouse database at the time of this INSERT INTO.

Edit2. I have ran the above query in management studio and it took 5s!?

Edit3. I have added a temporary CLUSTERED INDEX in a hope that this would assist this query, this has not helped either.

  • 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-06-12T10:47:57+00:00Added an answer on June 12, 2026 at 10:47 am

    This was caused by a DELETE query being run before a preceeding CREATE CLUSTERED INDEX query had time to update the entire table. The solution was to use the BEGIN TRANSACTION and COMMIT keywords. This forces SQL Server to finish the indexing before attampting anyother operations.

    Note, that this problem is only likely to arise when following a CREATE CLUSTERED INDEX query with a dynamic SQL statement that modifies the existing tabel.

    I hope this helps someone else.

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

Sidebar

Related Questions

I have built an ASP.NET MVC 2 website that I am hosting with Rackspace
I have built a MVC website on IIS6. I used the built-in ASP.NET Security
I have an ASP.NET MVC3 application that I have built and it has two
I have a console app built on .NET 4 that uses the HttpClient library
I have a data layer built on Linq-2-SQL in .net 3.5. We're looking at
I have built an application that uses the GestureRecognizer (System.Windows.Ink.GestureRecognizer). The problem is that
I have a system that takes information from an external source and then stores
I have built a web setup project in VS2008 which installs my ASP.NET/Silverlight app
Does .Net have any built in constants for common numbers like million, billion etc?
I have an app built in ASP.NET/C# . I have created a WebSetUp for

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.