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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:10:01+00:00 2026-05-23T10:10:01+00:00

I have a large database (50 million rows) containing time series data. There is

  • 0

I have a large database (50 million rows) containing time series data. There is a clustered index on the [datetime] column which ensures that that the table is always sorted in chronological order.

What is the most performant way to read the rows of the table out into a C# app, on a row-by-row basis?

  • 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-23T10:10:02+00:00Added an answer on May 23, 2026 at 10:10 am

    You should try this and find out. I just did, and saw no performance issues.

    USE [master]
    GO
    /****** Object:  Database [HugeDatabase]    Script Date: 06/27/2011 13:27:50 ******/
    CREATE DATABASE [HugeDatabase] ON  PRIMARY 
    ( NAME = N'HugeDatabase', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2K8R2\MSSQL\DATA\HugeDatabase.mdf' , SIZE = 1940736KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
     LOG ON 
    ( NAME = N'HugeDatabase_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2K8R2\MSSQL\DATA\HugeDatabase_log.LDF' , SIZE = 395392KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
    GO
    
    USE [HugeDatabase]
    GO
    /****** Object:  Table [dbo].[HugeTable]    Script Date: 06/27/2011 13:27:53 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[HugeTable](
        [ID] [int] IDENTITY(1,1) NOT NULL,
        [PointInTime] [datetime] NULL,
    PRIMARY KEY NONCLUSTERED 
    (
        [ID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    CREATE CLUSTERED INDEX [IX_HugeTable_PointInTime] ON [dbo].[HugeTable] 
    (
        [PointInTime] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    GO
    

    Populate:

    DECLARE @t datetime
    SET @t = '2011-01-01'
    
    DECLARE @i int
    SET @i=0
    
    SET NOCOUNT ON
    
    WHILE (@i < 50000000)
    BEGIN
        INSERT INTO HugeTable(PointInTime) VALUES(@t)
        SET @t = DATEADD(ss, 1, @t)
    
        SET @i = @i + 1
    END
    

    Test:

    using System;
    using System.Data.SqlClient;
    using System.Diagnostics;
    
    namespace ConsoleApplication1
    {
        internal class Program
        {
            private static void Main()
            {
                TimeSpan firstRead = new TimeSpan();
                TimeSpan readerOpen = new TimeSpan();
                TimeSpan commandOpen = new TimeSpan();
                TimeSpan connectionOpen = new TimeSpan();
                TimeSpan secondRead = new TimeSpan();
    
                try
                {
    
                    Stopwatch sw1 = new Stopwatch();
                    sw1.Start();
                    using (
                        var conn =
                            new SqlConnection(
                                @"Data Source=.\sql2k8r2;Initial Catalog=HugeDatabase;Integrated Security=True"))
                    {
                        conn.Open(); connectionOpen = sw1.Elapsed;
    
                        using (var cmd = new SqlCommand(
                            "SELECT * FROM HugeTable ORDER BY PointInTime", conn))
                        {
                            commandOpen = sw1.Elapsed;
    
                            var reader = cmd.ExecuteReader(); readerOpen = sw1.Elapsed;
    
                            reader.Read(); firstRead = sw1.Elapsed;
                            reader.Read(); secondRead = sw1.Elapsed;
                        }
                    }
                    sw1.Stop();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
                finally
                {
    
                    Console.WriteLine(
                        "Connection: {0}, command: {1}, reader: {2}, read: {3}, second read: {4}",
                        connectionOpen,
                        commandOpen - connectionOpen,
                        readerOpen - commandOpen,
                        firstRead - readerOpen,
                        secondRead - firstRead);
    
                    Console.Write("Enter to exit: ");
                    Console.ReadLine();
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a relatively large database tables (just under a million rows) that has
I have a large table (several million rows) in a MySQL (version 5.0) database
I have a large database (180k+ rows and growing fast) of location data and
We have a large POSTGRESQL transactional database (around 70 million rows in all), and
I have a large file, with 1.8 million rows of data, that I need
I have a SQL Server database with a large amount of data (65 million
I have a large database of normalized order data that is becoming very slow
I have a database table with a large number of rows and one numeric
I am working with a rather large mysql database (several million rows) with a
For work I'm dealing with a large database (160 million + rows a year,

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.