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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:44:11+00:00 2026-05-24T13:44:11+00:00

This is pseudo-code: Select count(score) from myTable join HisTable on myTAble.id = HisTable.id where

  • 0

This is pseudo-code:

Select 
    count(score) 
from 
   myTable
join 
   HisTable on myTAble.id = HisTable.id 
where 
   name='aaa'
group by 
   id 
having 
   count(score) > 3 
order by 
   (someField)

My question is about index. Where should I put the non-clustered index and the clustered index?
By which priority? (the aggregate? The order? The where? The join fields?)

  • 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-24T13:44:12+00:00Added an answer on May 24, 2026 at 1:44 pm

    In SQL Server, there are several basic considerations:

    • the clustering key is vitally important, and it should be chosen with care – it should be narrow, unique, static and possibly ever-increasing (the NUSE principle) – see Kim Tripp’s Ever-increasing clustering key – the Clustered Index Debate……….again! blog post for more detailed information on why those characteristics are important).

      So your clustering key should be narrow – 4-byte INT is ideal, it should be UNIQUE and static, and this is perfectly handled by some kind of an ID – especially if it’s an INT IDENTITY. GUID is significantly worse, variable-width VARCHAR fields are absolutely out of the question

    • every foreign key column in a child table referencing a parent table should be part of a nonclustered index. This significantly speeds up JOINs and other operations

    • any column used in a WHERE or ORDER BY clause also is a good index candidate.

    But mind you: indexing is an art and a balancing act. Each additional index adds more overhead – don’t overdo your indices! Less is often more. Try to

    • pick a good clustering key
    • put nonclustered indexes on each of your foreign key columns

    and then see if your app performs OK. If it does – fine, let it be. If not: try to isolate the offending queries, and try to tune those. Don’t over-do your indexing by tuning each individual query – an index that might benefit one query can severely impact another one. It’s a matter of finding the best set of indices for your entire application.

    Read Kim Tripp’s blog posts – all if you have the time. She’s the Queen of Indexing and offers tons of very valuable insights into what to do (and what not to do).

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

Sidebar

Related Questions

Given a query (pseudo-code): <cfquery name=myquery>SELECT * FROM stuff</cfquery> How do I get rid
This is not a full/correct MySQL query only pseudo-code: Select * from Notifications as
I am using pseudo-code here, but this is in JavaScript. With the most efficient
I'm having a problem moving from a situation where an Outer Join works, to
For this (pseudo code) example I have two tables in MySQL: member { id,
I have an object model that looks like this (pseudo code): class Product {
This is something I've pseudo-solved many times and have never quite found a solution
This question is coded in pseudo-PHP, but I really don't mind what language I
Running ipconfig /all shows a Teredo Tunneling Pseudo-Interface. What is that? Does this have
This is my first post here and I wanted to get some input from

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.