“Clustered index” and “Order by Clause”

前端 未结 5 1459
慢半拍i
慢半拍i 2021-02-06 00:28

Is there any difference between Clustered Index and Order by Clause?

I have to populate the Dropdown from the Master Table and followin

5条回答
  •  借酒劲吻你
    2021-02-06 00:52

    My first question is: What is the business use case? If the answer is "display the rows in name order", then ORDER BY Name.

    Since you mentioned that you already have a non-clustered index on Name anyway, you should be good to go.

    I also imagine that you will be filtering data on 'Name' anyway, so you'll already be making use of the index.

    My second thought: Are you prematurely optimizing this? Is the table going to have thousands or millions of rows? If not, you probably won't notice whether or not an index exists anyway. And if you do have thousands of rows, how well will the dropdown box behave without filtering?

    We can do a lot of guessing, so it is always best if you profile the queries in your environment.

    In general, you put a CLUSTERED INDEX on incrementing values (IDENTITY, creation dates, etc) or if the data is relatively static. Not every table requires a clustered index.

提交回复
热议问题