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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:51:42+00:00 2026-05-26T14:51:42+00:00

I have a logtable with (shortened for example) these columns: user | time |

  • 0

I have a logtable with (shortened for example) these columns:

user | time | uniqueid | msg

And there is a Primary Key on

user,time,uniqueid

and a Clustered Index on

user

Now the only three things that are done with this table are:

  • insert an entry
  • delete all entries older than x
  • select entries for a user (max 1k at a time)

The selects happen rarely, the inserts happen all the time, and deleting is once per night.

If I understand correctly, the clustered Index will make the select very fast.
Because of the amount of data I noticed that deleting will take a very long time, and i guess that this is even worse because of the clustered Index. Is this correct? Also it might as well be making the inserts alot slower (but the numbers are small at a time, so this might not be noticed so easily)

My Idea would be:

  • setting the Clustered Index to time
  • as the primary key is never really used (nothing referes to this table or anything) would it make sense to just drop it and create another Index on user for the selects?

What is the best way to optimize this?

  • 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-26T14:51:43+00:00Added an answer on May 26, 2026 at 2:51 pm

    Normally I would use an artificial primary key, but for a log table this doesn’t really seem to make much sense unless you’ve omitted a requirement where you deal with individual log records. In that case, it makes more sense to me to maintain your primary key using a non-clusted index with the columns in the order you specify. Change the clustered index to be on time instead of on user. The selects on user can use the index defined by your primary key and, while slowing down some, should still be reasonably fast as they can use an index scan instead of a table scan. Since user is the first column, that should be fairly fast even though the rows are no longer contiguous. Making the clustered index on time will dramatically speed up the deletes and likely reduce fragmentation as well. Since you’re still only maintaining two indexes, it shouldn’t affect your insert performance. In fact it may improve since the structure of the table will more closely mirror the way the data is inserted.

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

Sidebar

Related Questions

I have a database table for log messages and at any time there can
I have the following scenario: there are a database that generates a new logTable
I have a log that is really huge. (millions of rows) LogTable ------- ID
Have you ever seen any of there error messages? -- SQL Server 2000 Could
I have a button clicking which a storedproc runs for long time in buttons
I have a log table in my database which holds all user actions. In
I have a transaction log table that is updated each time a record is
I have a webapp that currently stores all of a user's searches into a
I have two tables User & User Log . User log table basically logs
I have a table in an RDBMS which logs the user logins. A user

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.