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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:35:41+00:00 2026-06-06T16:35:41+00:00

I have a web app that reads data from a SQL DB that contains

  • 0

I have a web app that reads data from a SQL DB that contains Message Tracking logs, for performance reasons I want to ensure there is never more than 2 days worth of logs in the DB.

Normally this is a simple challenge, just delete the records right with a delete statement?

Unfortunately not that simple for me, the table contains record counts in the millions and the delete statements take a while to run. Is there a way to make this any quicker?

I’m currently doing this:

DECLARE @CutOffDate datetime;
SET @CutOffDate = DATEADD(d, -2, GETDATE());

WHILE @@ROWCOUNT > 0
BEGIN
    DELETE TOP (2000) E12_MessageTracking
    WHERE [TimeStamp] < @CutOffDate;

    DELETE TOP (2000) E12_MessageTracking_Recipients
    WHERE [TimeStamp] < @CutOffDate;
END

I am running the bulk insert queries quite frequently so I need to be able to run the deletes frequently as well, but currently the task is “overrunning” on the delete statements and the scripts that run are not able to keep up with real time.

UPDATE:

This is the version info that you guys asked for:

Microsoft SQL Server 2008 R2 (RTM) – 10.50.1810.0 (X64) Feb 3 2012 17:19:10 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.1 (Build 7600: ) (Hypervisor)

For the indexes, the tables don’t have a PK/FK relationship, but they “link” on a field called MessageID. The problem is MessageID is not always filled in so I am using a sub field called InternalMessageID which links better. One of the problems i’ve encountered is that there are multiple lines in the E12_MessageTracking table for each message, that link to the E12_MessageTracking_Recipients table.

I’d love to have a proper relationship between these tables but right now I can’t as I have no way of identifying all of the items that relate to a message without using the pre-existing InternalMessageID or MessageID columns.

For indexes, they are as follows:

E12_MessageTracking

Index on the InternalMessageID column, with included columns set for Timestamp and Event

E12_MessageTracking_Recipients

Index on the InternalMessageID column, with included columns set for Timestamp and Recipient

Thanks,
Chris.

  • 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-06T16:35:44+00:00Added an answer on June 6, 2026 at 4:35 pm

    First thing I would consider is to make sure the tables have an index where TimeStamp is the first indexed column.

    More detail:

    If the Timestamp isn’t the first column and your query doesn’t filter on the columns that come before it, then the index can’t be used (imagine looking for a book in a library where you know the first letter of the second word).

    You can have a better idea by looking at the execution plan for the script in SSMS. If the query on E12_MessageTracking says a Table Scan, then no indexes are being used.

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

Sidebar

Related Questions

I have java app that uses Axis to get data from web service. web
I have a Rails web app that is used to gather data from an
I have a phone app that trys to GET data from my web api
I have a web app that works fine from all browsers (IE9, Firefox, Chrome,
we have a C++ Win32 DLL that reads data from Excel. The application uses
I want to develop an iPhone app that read data from the internet but
I'm writing a web-app for the iPad that will be loading data from a
I have a web app that manages a significant amount of project data. I
I have a web app that uses google app engine .In ubuntu ,I start
We have an web app that is talking to Netsuite via Netsuite's web services.

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.