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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:06:47+00:00 2026-06-01T01:06:47+00:00

WITH TOP 100000 (100k) this query is finished in about 3 seconds WITH TOP

  • 0

WITH TOP 100000 (100k) this query is finished in about 3 seconds

WITH TOP 1000000 (1mil) this query is finished in about 2 minutes

SELECT TOP 1000000
    db_id = IDENTITY(int, 1, 1), *
INTO dbo.tablename
FROM dbname.dbo.tablename

Actual execution plan is always:

clustered index scan 4% cost
top
top
compute scalar
insert (96% cost)
select into

The table has 1.3 mil rows and has an int primary key on first column

Can I speed it up somehow? I’m using SQL Server 2008 R2.

  • 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-01T01:06:48+00:00Added an answer on June 1, 2026 at 1:06 am

    Here is a complete script that shows that the 1 million takes less than ten times as long as 100,000. Your situation is likely slightly different, but this shows that the fundamentals are not the issue.

    The results show that 100,000 records takes 146 ms, and 1,000,000 records takes 1,315 ms.

    These results are from my desktop. If someone else could run the script and post their results, that would be very useful.

    Rob

    USE master;
    GO
    -- Drop database SourceDB
    IF EXISTS (SELECT * FROM sys.databases WHERE name = 'SourceDB') ALTER DATABASE SourceDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
    IF EXISTS (SELECT * FROM sys.databases WHERE name = 'SourceDB') DROP DATABASE  SourceDB;
    GO
    -- Create database SourceDB
    CREATE DATABASE SourceDB; 
    ALTER DATABASE SourceDB SET RECOVERY SIMPLE;
    GO
    USE SourceDB;
    GO
    -- Create table SourceDB.dbo.SourceTable
    CREATE TABLE dbo.SourceTable (
        ColID int PRIMARY KEY
    );
    GO
    -- Populate table SourceDB.dbo.SourceTable
    DECLARE @i int = 0;
    WHILE @i < 1300000
    BEGIN
        SET @i += 1;
        INSERT INTO dbo.SourceTable (ColID) VALUES (@i);
    END;
    GO
    -- Drop database Test1
    IF EXISTS (SELECT * FROM sys.databases WHERE name = 'Test1') ALTER DATABASE Test1 SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
    IF EXISTS (SELECT * FROM sys.databases WHERE name = 'Test1') DROP DATABASE  Test1;
    GO
    -- Create database Test1
    CREATE DATABASE Test1;
    ALTER DATABASE Test1 SET RECOVERY SIMPLE;
    ALTER DATABASE Test1 MODIFY FILE (NAME = Test1, SIZE = 3000MB, MAXSIZE = 8TB);
    ALTER DATABASE Test1 MODIFY FILE (NAME = Test1_log, SIZE = 3000MB, MAXSIZE = 2TB);
    GO
    USE Test1;
    GO
    IF EXISTS (SELECT * FROM sys.tables WHERE [OBJECT_ID] = OBJECT_ID('dbo.DestinationTable1')) DROP TABLE dbo.DestinationTable1;
    IF EXISTS (SELECT * FROM sys.tables WHERE [OBJECT_ID] = OBJECT_ID('dbo.DestinationTable2')) DROP TABLE dbo.DestinationTable2;
    GO
    DECLARE @n  int       = 100000;
    DECLARE @t1 datetime2 = SYSDATETIME();
    SELECT TOP (@n) db_id = IDENTITY(int, 1, 1), *
    INTO dbo.DestinationTable1
    FROM SourceDB.dbo.SourceTable;
    SELECT DATEDIFF(ms, @t1, SYSDATETIME()) AS ElapsedMs;
    GO
    DECLARE @n  int       = 1000000;
    DECLARE @t1 datetime2 = SYSDATETIME();
    SELECT TOP (@n) db_id = IDENTITY(int, 1, 1), *
    INTO dbo.DestinationTable2
    FROM SourceDB.dbo.SourceTable;
    SELECT DATEDIFF(ms, @t1, SYSDATETIME()) AS ElapsedMs;
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Query 1: Top 10 codes that takes maximum time select top 10 source_code, stats.total_elapsed_time/1000000
I have following SQL query SELECT TOP 10000 AVG(DailyNodeAvailability.Availability) AS AVERAGE_of_Availability FROM Nodes INNER
SELECT TOP 5 Notices.Id, NoticeL.Notices_Id, Loc.Id as Location_Id, CAST(Notices.Text AS TEXT) as Text, CAST(Notices.Title
SELECT TOP 5 Notices.Id, NoticeLoc.Notices_Id, Loc.Id as Loc_Id, CAST(Notices.Text AS TEXT) as Text, CAST(Notices.Title
I've got the top menu on this page, implemented as a list (UL with
If I did a command like: SELECT TOP(10000) ProductId from ProductInfo WHERE ProductId IN
SQL SERVER 2000: I have a table with test data (about 100000 rows), I
When I run this code, the number at the top of the output window
I want to select max Id from nested select. Here is the my query:
I have a table that looks like this: ------------------------------------------------------------------- CUSTNUM (INT), ITEMNUM (INT), MONTH

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.